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.
Learn ADO.Net Entity Framework: Performing Basic CRUD Operation
Working With the DataTable Class in C#
Simple and very usefull code
Glad you figured it out :) enjoy coding
I figured it out. I did not see the part where you say you are doing this in a console applicaiton. I thought that the Data node and the Entity Data Model were for a new project. Of course that is silly. When I read this article the first time, I was busy editing it so I was looking for things to change and I did not read it closely enough. So yes if I create a console application first then when I add items to that I have a Data node and I can then add an ADO.Net Entity Data Model.
Ideally it should be .. seems installation is corrupted :( try reinstalling and select repair option it should be there
I am using Visual Studio 2010 Professional and I do not have a Data node in the Visual C# installed templates.