Inserting and Updating using Linq-2-SQL

sevendet

New Member
L2SQL seems great as long as I stick to read-only operations. As soon as I need to start changing fields, things get a bit hairy.In particular, I'm running in to two distinct problems.First, I'm attempting to populate a table with an arbitrary number of rows. The schema is mostly irrelevant, but it does have a 'BIGINT' primary key which is the identity column.Since the primary key is an identity, I'm not setting it before calling Table.InsertOnSubmit() or Table.InsertAllOnSubmit(), and I'm yielding a DuplicateKeyException: "Cannot add an entity with a key that is already in use."My second concern stems from the need for a LINQ equivalent to the following SQL statement:\[code\]UPDATE dbo.someTable SET someCol = 'someValue' WHERE pkValue = http://stackoverflow.com/questions/764829/20\[/code\]If I query the needed row first, then change someCol's value before a DataContext.SubmitChanges(), all is fine.However, I'm seeking a solution that doesn't require me to query the row first. In other words, if the primary key is a known quantity, how can this be executed?
 
Back
Top