tags:

views:

37

answers:

1

Hi,

Do you have to write update statements with Linq to SQL?

+2  A: 

Kinda. You can use it somewhat like an ORM in that you can update your in-memory data model, and then execute a dynamically generated UPDATE statement when you submit changes. For example:

using (MyDataContext db = new MyDataConext())
{
     db.Clients.First().Salary = 50000;
}

does not perform an update, but

using (MyDataContext db = new MyDataConext())
{
     db.Clients.First().Salary = 50000;
     db.SubmitChanges();
}

does.

JoshJordan
I have found that there is an attach error at times, so db.Clients.Attach(a) is needed. I found this to be an issue when looping through a list to change values.
James Black
James, can you post some example code where this might be necessary?
JoshJordan