Modify a row

After you have loaded a row from a database, the data context used to load row will track any changes you make. Changes are automatically updated to the database when you submit changes for the data context.
using (var ctx = SqlDataContext.CreateContext()) {
    Customer cu = ctx.Load<Customer>(query => query.CustomerID = 1);
    cu.ContactName = "<new contact name>";
    ctx.SubmitChanges();
}

or
using (var ctx = SqlDataContext.CreateContext()) {
    Customer cu = new Customer() { CustomerID = 1 };
    cu.Load(ctx);
    cu.ContactName = "<new contact name>";
    ctx.SubmitChanges();
}


You can load a fetch or a query either using Load<> method found in the data context or Load method of a fetch class. Queries offer several versions of Load methods. See Sorting, paging and filtering queries for more information.

After load you just change values of properties to new values and submit changes.

Delete a row

Last edited Oct 26, 2010 at 8:50 AM by nolics, version 3

Comments

No comments yet.