Code First in Entity Framework

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.




Recent Articles

Get 100% Code Coverage for Salesforce Custom Metadata Based Decisions

January 18, 2018 | Bohdan Dovhan

How to obtain a full coverage for code which uses Custom Metadata for strategy-like decision implementation? Introduction Many applications use configuration data. Configuration data might be relevant to the entire organization, or a subset of user, or even different for each user. For the purposes of this article, we will focus only on global configuration […]

Logging of Exceptions in Salesforce

January 11, 2018 | Mykola Senyk

Unpredicted behaviour in a custom code. Can we eliminate it? The ability to customize your Salesforce org code is not just a “nice to have.”  It greatly increases the capability and flexibility of Salesforce. However, custom code can also be tricky to use. It would be great if we could detect unpredicted behavior in our […]

© Copyright - CoreValue 2018
Salesforce, Sales Cloud, and others are trademarks of, inc., and are used here with permission.
Used with permission from Microsoft.