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.




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

Part 2: Optimizing and scaling microservices. Organic growth of eco-systems.

October 11, 2017 | Nikola Krastev

A microservices approach is not a silver bullet for all software architecture problems. It introduces tradeoffs and challenges of its own. However, process gains and improvements in human performance have been considered to be worth the overhead in technology. Here are some general arguments against using sophisticated SOA. Server performance and overhead in communication By […]

CoreValue President at IT Arena 2017

September 27, 2017

We are pleased to announce that CoreValue president Igor Kruglyak will participate in IT Arena 2017, to be held in Lviv, Ukraine, September 29 – October 1, 2017.