This article is a walkthrough of performing basic CRUD operations using the ADO.Net Entity Framework.Database design I am going to use a School Database. You can find the School database script here. To be precise, I am going perform CRUD operations on only one table; Person. The schema of the Person table is as below.I am going to perform CRUD operations on the Person table from a console application. Create Data Model
using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace ADONetEntityModelfirstDemo{ class Program { static void Main(string[] args) { #region Reterive a Person SchoolEntities entities = new SchoolEntities(); var result = from r in entities.People select r; foreach (var r in result) { Console.WriteLine(r.PersonID + r.LastName); } Console.ReadKey(true); #endregion #region Add a Pesron entities.People.AddObject(new Person { FirstName = "dhananjay", LastName = "kumar" }); entities.SaveChanges(); #endregion #region Modify a Person Person personToModofy = (from r in entities.People.Where (a => a.PersonID == 1) select r).FirstOrDefault(); personToModofy.LastName = "Jamshedpur"; entities.SaveChanges(); #endregion #region Delete a Person Person personToDelete = (from r in entities.People.Where (a => a.PersonID == 1) select r).FirstOrDefault(); entities.People.DeleteObject(personToDelete); entities.SaveChanges(); #endregion #region Reterive a Person var result1 = from r in entities.People select r; foreach (var r in result1) { Console.WriteLine(r.PersonID + r.LastName); } Console.ReadKey(true); } #endregion }}In a future article, we will discuss other aspects of the ADO.Net Entity framework. I hope this article was useful. Thanks for reading.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: