Entity Framework 4.0 FAQ – Getting Started Guide

Posted by: Suprotim Agarwal , on 11/1/2010, in Category Entity Framework
Views: 122731
Abstract: In this article, I will introduce Entity Framework 4.0, the history behind this framework and why it has become the recommended LINQ-based Data Access technology over LINQ To SQL, all in a simple Q & A format

When Entity Framework (EF) 3.5 was first released in 2008, I cried out ‘What the heck’, just like many other developers did across the world. As misunderstood as this technology was, some found it buggy while others felt it was complex. There was also a ‘natural’ resistance from the developer community, especially the ones working on LINQ To SQL a.k.a. Linq2Sql. They simply could not find a good reason for using EF 3.5 over LINQ to SQL.

However with the Entity Framework 4.0 release this year, developers have changed their opinion. In this article, I will introduce Entity Framework 4.0 to DotNetCurry readers, the history behind this framework and why it has become the recommended LINQ-based Data Access technology over LINQ To SQL, all in a simple Q & A format.

Note: I will be starting this new series of articles on Entity Framework (EF 4.0). So stay tuned if you want to learn EF 4.0! One way is to Subscribe to the RSS Feed and stay updated.

What is Entity Framework 4.0? Why do we need a new Data Access Technology?

All these years, Microsoft has been providing different ways to communicate with the Database. Developers have been switching from one data access technology to the other, starting with DAO (Data Access Objects), then RDO (Remote Data Objects), then ADO (ActiveX Data Objects) and then finally ADO.NET. ADO.NET has been around from quite some time and Microsoft has invested a great deal of resources in it, with new features added to it every now and then. Although working with the DataSet and DataReader has served our data access needs for many years, a developer spends a lot of time being concerned with the details of the schema, trying to keep up with database schema changes and doing redundant tasks while interacting with the database, over and over again.

The ADO.NET Entity Framework (EF) is an Object/Relational mapping (ORM) framework and is a set of technologies in ADO.NET, for developing applications that interacts with data. We just discussed that an ADO.NET developer spends a lot of time keeping up with the database changes. Well EF provides a mapping from the relational database schema to the objects and offers an abstraction of ADO.NET. So with EF, you can define Entity classes that are independent of a database structure and then map them to the tables and associations of the database. Since we are now working with Entities which have their own schema, we are shielded from the changes in the database. The object context keeps tabs on the entities that are changed.

In simple words, with the Entity Framework, you are architecting, designing and developing at a conceptual level. You are no more worried about the ‘specific details’ of communicating with the database and switching from one relational database to the other is also possible with EF, without much efforts.

What happens to ADO.NET now?

ADO.NET is here to stay! EF was not released with the intension to replace ADO.NET. It is in fact an enhancement to ADO.NET and helps eliminate the gap between the application and the database. Behind the scene, EF uses ADO.NET classes, but the details are abstracted from you. EF provides a shift from Database-oriented (DataReader, DataSet) to Model-oriented development. So instead of focusing on a Database, a developer focuses on the Entity that represents the Business Model of the application.

If the purpose of EF is not yet clear, it will be, in the forthcoming articles when we will explore its features and look at it in detail. Continue reading as I am about to explain why EF was chosen over LINQ To SQL!

When was Entity Framework Released?

Although announced in TechEd 2006, the first version of Entity Framework 3.5 was released two years later in August 2008, along with Visual Studio 2008 SP1 and .NET 3.5 SP1.

The second version (also the current version) of Entity Framework i.e. 4.0 was released in April 2010 along with VS 2010 and .NET 4.0.

What happened to LINQ To SQL?

When .NET 3.5 and Visual Studio 2008 was being released in November 2007, a lot of focus was on LINQ. The original plan was to release EF along with VS 2008/.NET 3.5 and introduce developers to this new LINQ based data access technology. However the scale of EF caused a delay and it could not be released along with VS 2008.

Meanwhile, LINQ To SQL (L2S), worked upon by a different team at Microsoft was ready to release. Since one of the focuses of the VS 2008 and .NET 3.5 release was on LINQ, it made a lot of sense to release a LINQ Provider along with VS 2008. So during that time, L2S became the original LINQ provider for data access. In my honest opinion, L2S was kind of a bait to attract developers towards LINQ data access, while the team continued working on EF, i.e. the real beast.

Finally when EF 3.5 was released in August 2008, it could not get the attention from the developer community, for obvious reasons. L2S was gaining popularity primarily due to it being lightweight, simple and easy to use technology and the fact that most of the .NET apps targeted SQL Server, there was a resistance to adopt a new framework (EF) from the dev community. EF remained a misunderstood technology, there were issues in the framework and although accidental, L2S was still believed by many as the original LINQ provider for data access. EF had a lot to prove!

However with the release of EF 4.0 with .NET 4.0, things have changed, including opinions. Microsoft made it clear that although L2S was supported, it was not the recommended technology. Moreover with the new features like POCO support, Model First Development and Custom Code Generation, developers started looking at EF 4.0 and consider it seriously as the preferred ORM solution for enterprise apps.

LINQ To SQL Vs Entity Framework

There are some fundamental differences between L2S and EF which every developer should understand. Both EF and L2S provide a framework for managing relational data as objects, with the objective of programming against a conceptual model rather than a DB schema.

However LINQ To SQL supports rapid development of applications that query only SQL Server and SQL Server Compact 3.5 databases, providing a 1:1 mapping of your existing Database schema to classes. It does not provide the flexibility to use objects that do not exactly match the tables.

EF on the other hand, supports advanced modeling features and ‘loosely coupled and flexible’ mapping of objects to SQL Server. Through extended ADO.NET Data Providers, EF supports other relational databases as well, including Oracle, DB2, MySql etc. EF also allows objects to have a different structure from your database schema.
Although LINQ To SQL (L2S) is supported by Microsoft, it is not recommended. Entity Framework (EF) is definitely the way to go if you are working on something bigger (enterprise apps), need the flexibility of a solid framework, with the support for multiple databases and much more!

Note: LINQ to Entities is part of the Entity Framework and exposes many of the same features as L2S. It has replaced L2S as the standard mechanism for using LINQ on databases.

How do I get Started with Entity Framework 4.0?

Well if you have continued reading so far, I assume you are interested in Entity Framework 4.0 and are ready to explore the future of data access. The easiest way to get started with it is to download and install Visual Studio 2010.

The Entity Framework 4.0 is part of .NET 4.0, so both Visual Studio 2010 and the .NET 4.0 provide you with the necessary tools and technologies to begin developing. So you can either download the Visual Studio 2010 Ultimate Trial Edition or get the free Visual Studio 2010 Express Edition.

Update: Check the next articles in this series

Create an Entity Data Model From a Database – Entity Framework 4.0

Exploring how the Entity Data Model (EDM) Generates Code and Executes Queries – Entity Framework 4.0

Model-First Development in Entity Framework 4.0 - Create a Database from a Model

Create an Entity Framework Model and Use it in Multiple Projects

Add, Update and Delete Objects in Entity Framework 4.0

Bind Entity Framework 4 Model to ASP.NET GridView

Profiling and Logging Entity Framework Queries

I hope you liked the article and I thank you for viewing it!

This article has been editorially reviewed by Suprotim Agarwal.

Absolutely Awesome Book on C# and .NET

C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.

We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).

Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.

Click here to Explore the Table of Contents or Download Sample Chapters!

What Others Are Reading!
Was this article worth reading? Share it with fellow developers too. Thanks!
Share on LinkedIn
Share on Google+

Suprotim Agarwal, MCSD, MCAD, MCDBA, MCSE, is the founder of DotNetCurry, DNC Magazine for Developers, SQLServerCurry and DevCurry. He has also authored a couple of books 51 Recipes using jQuery with ASP.NET Controls and The Absolutely Awesome jQuery CookBook.

Suprotim has received the prestigious Microsoft MVP award for ten consecutive times. In a professional capacity, he is the CEO of A2Z Knowledge Visuals Pvt Ltd, a digital group that offers Digital Marketing and Branding services to businesses, both in a start-up and enterprise environment.

Get in touch with him on Twitter @suprotimagarwal or at LinkedIn

Page copy protected against web site content infringement 	by Copyscape

Feedback - Leave us some adulation, criticism and everything in between!
Comment posted by SkillForge .NET Training on Monday, November 1, 2010 5:11 PM
This is an EXCELLENT overview. These somewhat overlapping technologies are confusing at the very least - even for experienced developers. Pingback from the SkillForge blog.
Comment posted by Kevin Bernier on Monday, November 1, 2010 6:52 PM
Outstanding article. I am now eager to learn more on ef 4 and look fwd to your next articles. 10 on 10
Comment posted by Best Web Design on Tuesday, November 2, 2010 2:29 AM
nice post. nice information sharing. Now a days, its difficult to find articles which teach.
Comment posted by Sean Hederman on Wednesday, November 3, 2010 10:28 AM
I would disagree with the overall thrust of the article. EF 4 is mindbogglingly buggy, with major issues in the designer as well as the underlying technology. Although it supports cross-table inheritance, this requires you re-editing the designer XML on each refresh. Oh, and it does NOT support POCO, unless you consider that having to utterly change your classes is POCO. Oh yeah, and it doesn't support enums. Enums for goodness sakes.

Comment posted by Suprotim Agarwal on Saturday, November 6, 2010 1:05 AM
Sean: Thanks for your comments. I am not sure what you mean by no support for POCO. Using POCO classes is another way to create your EDM, by writing domain classes with the same structure as your DB schema. It gives a good amount of flexibility, with a separation of assemblies containing your EF classes and POCO classes.
Comment posted by Altaf Khatri on Monday, November 15, 2010 5:11 PM
The other difference between Entity Framework and L2S is about serialization of objects. EF objects are serializable where as L2S objects are not serializable, important difference if you intend to save the objects out of proc for web applications.
Comment posted by Martin on Friday, November 19, 2010 12:07 AM
That's a good point by altaf about serialization. thanks for sharing
Comment posted by Raffy on Wednesday, December 22, 2010 6:30 AM
Thank you very much about your article. Its very very helpful and easy to understand. I hope its not too much to ask, uhm, can you also add a tutorial on how to use this EDM with Web services or WCF or there's no need to go this far. Am planning to use this new tech with my new intranet web app (around 18k concurrent users with around 8 Million data).

Thanks Much and looking forward on your reply.
Comment posted by Suprotim Agarwal on Thursday, December 23, 2010 3:02 AM
Raffy: Glad you liked it. I will soon write an article that shows how to use EDM with a WCF service.

Btw, we recently published an article written by Mahesh that showed how to create a Line of Business (LOB) Application using Silverlight 4, WCF 4, Entity Fw 4 and Commanding Architecture. Check it here http://www.dotnetcurry.com/ShowArticle.aspx?ID=621

Comment posted by D on Monday, January 16, 2012 3:01 PM
is it supported for oracle 10g
Comment posted by Arun Mariappan K on Wednesday, January 18, 2012 12:48 AM
Your articles on Entity Framework are all really helpful and detailed. Many Thanks... :)
Comment posted by Sumit Kapadia on Wednesday, December 12, 2012 12:52 AM
Great article for a EF newbies. I really want a line between L2S and EF and yes you drawn it.

Comment posted by amrinder on Friday, May 17, 2013 12:23 AM
Not well directed
Comment posted by Vibin Mathew on Friday, May 17, 2013 3:42 AM
Perfect!!! I couldnt find an article which made me interesting about EF. Thanks
Comment posted by international trade on Monday, June 3, 2013 7:56 AM
Free of charge classified ads pertaining to USA. Submit your Advertisement. National cost-free ads.
Comment posted by small business logo design on Monday, November 11, 2013 12:20 PM
Have you learned all the charisma of logo designing? Do you think now yourself a master in the designing field? Well, you have to learn yet more things to be a successful designer. It is not just an important thing to invest all your creativity with great attention.
Comment posted by Limo Mississauga on Saturday, January 18, 2014 9:36 AM
Limo services for such wonderful occasions are mostly outstanding. Only most excellent

cars are Limo Mississauga availed for those who are receiving married to make sure that

you create a grand look and a horizontal grander exeunt. The services that are naturally

available will need you to build a stipulation of the best journey that you would desire

to present transport for your particular day.
Comment posted by Brampton Wedding Limo on Monday, January 20, 2014 11:51 AM
We are committed to offering our customers just the exact freshest, most dynamic and creative limousines ever fabricated, and to backing our limousines with qualified completely prepared escorts who mind. Escorts who consideration to have an effect, determining your exceptional event runs easily; in complete extravagance and that you land on time, push free and primed to appreciate your enormous night or day out.http://bramptonlimorental.com/
Comment posted by Brampton Limo on Tuesday, January 21, 2014 11:54 AM
Our wedding limo Toronto contract organization has practical experience in offering choice limousine contract administrations for weddings. As an encountered organization in the wedding limousine employ, we comprehend the necessities of our client’s superior to whatever possible wedding limo contract organization. We realize that your wedding is the most critical day of your life, you will need only the best for your wedding and that is the reason we put in additional endeavors to deal with your wedding limo Brampton contract needs.
Comment posted by sophia on Sunday, April 20, 2014 1:20 PM
Hello sir,

Really helpful and simple to understand.
But I want to ask that is there any article series on your site which covers all LINQ coding style with code samples or you know any other article of the same or book, please suggest me.

Code sample you have shown are very few, but after I have read your this series I am willing to learn LINQ coding.
So please tell me any linq article series or book.

Thank you.
Comment posted by Suprotim Agarwal on Monday, April 21, 2014 11:49 AM
@Sophia: Please refer to http://www.dotnetcurry.com/showarticle.aspx?ID=564