Archives

Code First in Entity Framework

September 4, 2012

There are two .Net ORM approaches natively supported by Microsoft: Linq2SQL and EntityFramework. While the future of the Linq2SQL is unknown EntityFramework is being actively developed.

EntityFramework provides a whole bunch of advanced ORM features including a large variety of supported mappings, a useful model designer, and auto-generation of model classes. But a lot of developers don’t like all this heavy stuff, which requires careful separation of auto-generated code from custom code, and dealing with a visual editor and huge XML files, which is in fact less productive for developers than simple code writing.

That is why, starting from EF4.1, the Code First approach appeared alongside the DB First and Model First approaches, as a natural resolution of the problem.
This approach enables writing simple POCO (Plain Old CLR Objects) model classes first and then connecting those POCO classes with the database very easily by using the the DbContext class.

References to other POCO objects and collections are recognized automatically as object relations including many-to-many. To override and extend standard mapping rules, Fluent API or/and Data annotations are used.

A lot of developers also find Code First approach very useful in case of multiple DB support – you don’t need to regenerate any models – just use a new connection to the DB.

Recently Entity Framework 5.0 has been released. This version provides some performance enhancements and a list of new features, such as support of enums and table-valued functions (only available when writing an application that targets .NET 4.5). Mapping to stored procedures is still not supported.

Tags

News

Share


0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Articles

Weathering the Storm

September 22, 2017

As everyone is aware, over the first half of September, Hurricane Irma brought huge devastation to the Caribbean and Florida, with islands all but destroyed and more than 6 million Floridians lacking power.

9 Big Things about Java 9

September 15, 2017 | Andrew Petryk

According to the latest Tiobe index of programming language popularity, Java tops the list.  No wonder there is so much buzz around the new Java 9 release, set for September 21, 2017.  Take a walk through with our expert.     1. JSHELL Many compiled languages include tools for statements interpretation. By using these REPL tools […]