.NET FAQs Unleashed!
 
    
    

Does the Entity Framework support CRUD operations? Where do we use the SaveChanges method?

Yes, the Entity Framework (EF) supports CRUD (Create, Read, Update, Delete) operations.

The SaveChanges method is used in update operations. In the Entity Framework, the records in the transaction are not updated immediately. Rather, the save all the statements in the end when all properties are updated. Check out the example below:

using (var = dbContext = new SomeEntities())
{
   var purchaseQuery = from Employer in dbContext.Employers
   where employer.EmployerID == 123
   from order in employer.PurchaseOrderHeaders    orderby order.PurchaseOrderDate descending
   select order;

//Now see above that multiple statements are specified

PurchaseOrderHeader latestOrder = orderQuery();
latestOrder.Comment = "Request employer for payment";
dbContext.SaveChanges();

ADO.NET Base Classes   DataSet Advantages   SQL Queries through String Concatenation   Deferred Execution in LINQ   Object LINQ Provider VS. Database LINQ Provider   .edmx file   ADO.NET Entity Framework   Silverlight connections to databases   Multiplicity and Degree in Entity Framework   NHibernate   WCF Data Services   Optimistic Concurrency | OptimisticConcurrencyException   TransactionScope Class   Entity Framework and CRUD   Lazy Loading  

More Interview Questions...