views:

424

answers:

1

Yes, this subject is covered on hundreds of posts all over the net, and yet I still haven't found the one that doesn't involve loading an entire entity (sometimes serialized) just to change a single field. Some had suggested that changing "Update Check" on all properties of the entities would resolve this, but so far I'm still getting ChangeConflictExceptions no matter my approach. Is there any way to just tell L2S to stop being my nanny and let me update?

var context = new MyDataContext();
var person = new Person() {Id = 5};
person.LastName = "Johanssen";
context.People.Attach(person);
context.SubmitChanges();

Thanks so much for your insight!

James

+1  A: 

Ok, I wasn't watching Visual Studio closely enough. Even though in the designer I had changed all my fields to UpdateCheck.Never when I looked at the MyModel.desinger.cs file to see the generated entities, that attribute wasn't being added to most of the fields. When I added the attribute, the update went through and all was well.

If you need to add this attribute to many fields at once, here is a VS Regular Expression replacement that will append it to all the columns in the file. I HIGHLY suggest checking the file in (or backing it up) first to make sure you don't lose all your hard work first. And if you already have the attribute set on some, it will double them up (thus the second replacement below).

Find and Replace (Regular Expressions on)
\[Column{.*}\)\]
[Column\1, UpdateCheck=UpdateCheck.Never )]

Find and Replace (Regular Expressions off)
UpdateCheck=UpdateCheck.Never, UpdateCheck=UpdateCheck.Never  
UpdateCheck=UpdateCheck.Never