entity framework - save changes to entities
To save the changes made to the entities to a database, we need to call the ObjectContext class SaveChanges method. In the example given below, the query retrieves the first customer from the entityset -Customer.
The context.Customer returns the Objectset of Customer types and the LINQ extension method First()returns only the first customer.
We can edit the first customer details like name and address by assigning new values to the properties and call the SaveChanges() method to save the changes back to the database.
During SaveChanges, the ObjectContext determines which fields were changed. In this example, only name and address are changed. So, only those two values are sent into the command. To identify the row to be updated in the database, the ObjectContext uses the value of the EntityKey property.
using (var context = new SalesOrderManagementEntities()) { var Customer = context.Customer.First(); Customer.Name = "BHA"; Customer.Address = "address1"; context.SaveChanges(); //The below query is for displaying the customer details after edit operation var query = from c in context.Customer select c; foreach (var c in query) { Console.WriteLine(String.Format("{0} {1}", c.Name, c.Address)); } Console.WriteLine(); Console.ReadLine(); }
Entity Framework Articles
- entity framework entity data model
- entity framework orm object relational mapper
- querying entity data model using objectcontext
- using ado net entity data model in windows applications.html
- create entity data model using ado.net entity framework designer in visual studio
- create-sales-order-management-data-model-using-edmgen-tool.html
- display data in a gridview using ado.net entity data source control
- ways of querying entity data model
- query entity data model using linq to entities
- query entity data model with object services and entity sql
- query entity data model using linq methods
- parameterized objectquery against a entity data model
- query entity data model entity client
- linq to entities query with projections in c#
- entity framework - insert new objects
- add an entity to associated entities
- deleting entities using deleteobject() method of objectcontext
- entity framework load method
- eager loading using include method in entity framework
- entity framework - retrieving a single entity
Most Viewed
Azure Q & A
Azure Platform
Grid-View
GridView CommandField example
Details-View
GridView and DetailsView Master/Detail page using SqlDataSource control
POCO
POCO overview and advantages - POCO class, Entity Framework in Enterprise Applications
Entity Framework
Query entity data model using linq to entities
Array List
Difference between arraylist and list collection
Web Services
How to create a Web service using Visual Studio.net
Form-View
FormView DataBound Event
Object Oriented Programming
Calling base class constructor in C#
Linq
Convert a sequence to a generic list using ToList()method
Project Ideas
Project ideas for students
AccountingSoftware
Accounting Software
MVC
Creating an ASP.Net MVC 3 application
.Net
Using assemblies in .net applications
ASP .Net
How to implement form validation using ASP.Net 2.0 Validation Controls
VB .Net
Constructors in Visual Basic.Net