How to create an ADO.NET Entity Framework Model in .NET 3.5 Framework?

Here are the software/installer that you need before using ADO.NET Entity Framework:

Visual Studio 2008 Professional Edition/Team System Edition

.NET Framework 3.5

Microsoft SQL Server 2005

.NET Framework 3.5 Service Pack 1

Visual Studio 2008 Service Pack 1

Second, Create a class library, right click Add Then New Item Then look for ADO.NET Entity Data Model.

Step 1 – Right click your project. Then click add then click new item.

Step 2 – Type your chosen name for this entity model that ends with .edmx.

Step 3 – click next.

Step 4 – choose your connection or create a new connection. Just click Yes, to include connection string. If you wish to change the connection string. Just click the “New Connection…” button to change the connection. Type your chosen connection string name that will be saved in your app.config or web.config.

Step 5 – Choose the tables, views, store procedures that you wish to include in this entity model. Type your chosen name for the model namespace. Then click finish.

Step 6 – It will generate all your entity object and will display all the tables, view, stored procedures that you have chosen.

Third, create a separate Business Layer, a class and interface for each table in the tables.

A sample of simple CRUD in Linq to entity:

        ChosenEntityName dbEntity;

        Cities city;

        List<Cities> cityList;

        string connString =    ConfigurationManager.ConnectionStrings[“ChosenConnectionStringName”].ConnectionString;

        public CitiesBLL()


            dbEntity = new Entity(connString);

            city = new Cities();

            cityList = new List<Cities>();


        public Cities RetrieveCityById(int id)


            city = (from c in dbEntity.Cities

                    where c.CityID == id

                    select c).FirstOrDefault<Cities>();

            return city;


        public List<Cities> RetrieveCityList()


            cityList = (from c in dbEntity.Cities

                        select c).ToList<Cities>(); 

            return cityList;


        public int InsertCity(Cities citys)



            return dbEntity.SaveChanges();


        public int UpdateCity(Cities citys)


            city = (from c in dbEntity.Cities

                    where c.CityID == citys.CityID

                    select c).FirstOrDefault<Cities>();

            city.CityCode = citys.CityCode;

            city.CityName = citys.CityName;

            city.CountryID = citys.CountryID; 

            return dbEntity.SaveChanges();


        public int DeleteCity(int id)


            city = (from c in dbEntity.Cities

                    where c.CityID == id

                    select c).FirstOrDefault<Cities>();


            return dbEntity.SaveChanges();


If you are joining two or more tables, here is your linq:

            var data = (from c in dbEntity.Cities

                        join co in dbEntity.Countries

                        on c.CountryID equals co.CountryID

                        where c.CityID == id

                        select new








I hope this tutorial will help you.

Here are the other references that  I used:

This entry was posted in C# 3.5 and ADO.NET Entity Framework 3.5, Linq to Entity and tagged , . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s