Using linq to sql for data update method?

1 answer

Answer

1161694

2026-08-03 15:25

+ Follow

To update data using LINQ to SQL, you first need to retrieve the entity you want to modify from the database context. After making the necessary changes to the entity's properties, you call the SubmitChanges() method on the data context to persist the updates to the database. Here's a simple example:

<code class="language-csharp">using (var context = new YourDataContext())

{ var item = context.YourTable.SingleOrDefault(x => x.Id == itemId); if (item != null) { item.Property = newValue; // Update the property context.SubmitChanges(); // Commit the changes } }

</code>

This ensures that the changes are correctly tracked and saved.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.