2
Reply

How to Read, Add, Update and Delete record in Entity Framework ?

Kumar Bhimsen

Kumar Bhimsen

8y
716
0
Reply

    check thishttp://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/implementing-basic-crud-functionality-with-the-entity-framework-in-asp-net-mvc-application

    For performing the CURD operation in EF. We have to use an object of context class. Example: To Read data record : CustomerContext obj = new CustomerContext(); Foreach(Customer cust in obj.customer) { // Do your work here. } To add data record: we use AddObject method and savechange method to add record. CustomerContext obj = new CustomerContext(); Customer custObj= new Customer(); custObj.Name=”Bhimsen”; custObj.Email=”[email protected]”; custObj.Mobile=8010326915; custObj.Address=”New Delhi”; obj.customer.addobject(custObj); obj.savechanges(); To Update Record : CustomerContext obj = new CustomerContext(); Customer custObj= (Customer) obj.Customer.firstOrDefault(); custObj.Name=”Bhimsen”; obj.AcceptAllChanges(); To Delete Record: CustomerContext obj = new CustomerContext(); Customer custObj= (Customer) obj.Customer.FirstOrDefault(); Obj.DeleteObject(CustObj);