KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm in a world of pain with this one, and I'd very much appreciate it if someone could help out. I have a DataContext attached to a single test table on a database. The test table is as follows: CREATE TABLE [dbo].[LinqTests]( [ID] [bigint] IDENTITY(1,1) NOT NULL, [StringValue] [varchar](255) NOT NULL, [DateTimeValue] [datetime] NOT NULL, [BooleanValue] [bit] NOT NULL, CONSTRAINT [PK_LinqTests] PRIMARY KEY CLUSTERED ([ID] ASC)) ON [PRIMARY] Using Linq, I can add, retrieve and delete rows from the test table, but I cannot update a row -- for an UPDATE, I always get a ChangeConflictException with an empty ObjectChangeConflict.MemberConflicts collection. Here is the code used: var dataContext = new UniversityDataContext(); dataContext.Log = Console.Out; for (int i = 1; i <= 1; i++) { var linqTest = dataContext.LinqTests.Where(l => (l.ID == i)).FirstOrDefault(); if (null != linqTest) { linqTest.StringValue += " I've been updated."; } else { linqTest = new LinqTest { BooleanValue = false, DateTimeValue = DateTime.UtcNow, StringValue = "I am in loop " + i + "." }; dataContext.LinqTests.InsertOnSubmit(linqTest); } } try { dataContext.SubmitChanges(ConflictMode.ContinueOnConflict); } catch (ChangeConflictException exception) { Console.WriteLine("Optimistic concurrency error."); Console.WriteLine(exception.Message); Console.ReadLine(); } Console.ReadLine(); Here is the log output for an update performed through the DataContext. UPDATE [dbo].[LinqTests] SET [StringValue] = @p3 WHERE ([ID] = @p0) AND ([StringValue] = @p1) AND ([DateTimeValue] = @p2) AND (NOT ([BooleanValue] = 1)) -- @p0: Input BigInt (Size = 0; Prec = 0; Scale = 0) [1] -- @p1: Input VarChar (Size = 15; Prec = 0; Scale = 0) [I am in loop 1.] -- @p2: Input DateTime (Size = 0; Prec = 0;
Tags (comma-separated)
Save Edits
Cancel