Insert, Update and Delete using C# LINQ to Entities Data Model
The LINQ to Entities ObjectContext provides the functionality to generate the SQL commands at runtime which enable to perform the insert, update, delete and select operations dynamically. LINQ to Entities translates the specified action into a SQL and submits the changes to the database. It offers high flexibility in manipulating and preserving the changes made to the data objects retrieved from the database.
LINQ to Entities work in a sequence according to the code statements written in the application. When a call is made to the data source to fetch and populate the entity objects you can change their values, add new objects to the collection or remove the objects from the collection. LINQ to Entities track your each and every change and submits them back to the database as soon as the SaveChanges method is called.
Any operation specified for inserting, updating or deleting an object is following by the SaveChanges method of LINQ to Entities. As soon this method is called in the code, it auto-generates SQL script based on the tracked changes and sends them back to the database.
The Delete operation of LINQ to Entities ObjectContext also supports cascade-delete operations. The following tutorials describe the LINQ to Entities data manipulation operations using C# code:
In the above tutorials we have provided short and simple examples to understand the flexibility of LINQ to Entities data operations.