Tuesday, July 8, 2014

Introduction to Entity Framework

Entity Framework (EF) is an object-relational mapper (ORM) for .NET. Entity Framework can be used to work with relational data using domain-specific objects. Entity Framework eliminates need for data access code that programmers usually need to write. The codes you write with Entity Framework will be converted to SQL queries. 

You can view them using ((System.Data.Objects.ObjectQuery)result).ToTraceString(); 
ObjectQuery class is the base class for queries against a conceptual model. There's also the ObjectQuery<T> generic class. 

Architecture of Entity Framework



Above diagram shows the high-level architecture of the Entity Framework. Conceptual model contains model classes and there relationshps this is independent from the actual tables in the database. For details of other components in the above diagram see this.

You can also check Entity Framework Overview available in MSDN

Workflows

In Entity Framework there are 3 workflows developers can use to start with. They are Model First, Database First and Code first. All of these has its own pros and cons so understanding the differences correctly is important.

Model First

Using Model First approach developers can create the Database model using ORM designer in Visual Studio. Here the designer relies on the .edmx file designer to maintain the design specifics. 

The physical database will be then generated from the model.

Database First

Using this approach you can reverse engineer a model from an existing database. The classes are automatically generated from EDMX file. Read Entity Framework Database First Example for steps.

In the wizard for creating the model, you'll get checkboxes to select Pluralize or singularize generated object names option. Read more about it here.  

Code First

Create classes first and generate Database from the classes directly. No use of Entity designer at all. 

Choosing the suitable workflow

Understanding which workflow to use is important before you start developing data access applications using EF. 

http://blog.smartbear.com/development/choosing-the-right-entity-framework-workflow/
http://msdn.microsoft.com/en-us/library/vstudio/cc853327%28v=vs.110%29.aspx  

Data Persisting in Entity Framework

Entity Framework use Unit of Work pattern to persist data. 

0 comments:

Post a Comment

Powered by Blogger.


Software Architect at Surge Global/ Certified Scrum Master

Experienced in Product Design, Software Engineering, Team management and Practicing Agile methodologies.

Search This Blog

Facebook