Entity Model changes between Visual Studio 2010 and Visual Studio 2012

Posted: (EET/GMT+2)

 

I'm a fan of Microsoft's Entity Framework (EF) and use it in many .NET applications I write. Although it doesn't fit all situations, it's a good solution for simple needs, and efficiently removes the need to manually work with SQL statements.

Now that Visual Studio 2012 is here, you might have noticed that there are some changes in the way Entity Models work and behave from your C# code. For instance, adding and deleting (removing) objects is now done with different syntax.

Firstly, a quick reminder on where you can verify your current EDMX model's version number. The .edmx file starts with the following XML tag in Visual Studio 2010:

<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx">

This corresponds to the entity model version 2. In Visual Studio 2012, a newly generated model starts with the following element:

<edmx:Edmx Version="3.0" xmlns:edmx="http://schemas.microsoft.com/ado/2009/11/edmx">

This change alone wouldn't mean much, but there are also changes in the way the entity model is manipulated in code. Here is a table of the most important changes; these are related to adding and removing entities, other main operations have stayed the same.

Feature Visual Studio 2010 example Visual Studio 2012 example
Creating the Entity Model NorthwindEntities entities = new NorthwindEntities(); (same)
Adding a new entity (new table row) entities.AddToCustomers(cust); entities.Customers.Add(cust);
Deleting an entity (remove table row) entities.DeleteObject(cust); entities.Customers.Remove(cust);
Updating entity values cust.CompanyName = "Acme, Inc."; (same)
Saving changes to database ("commit") entities.SaveChanges(); (same)

Hope this helps!

Keywords: Compare Visual Studio 2010 Entity Model to Visual Studio 2012; Differences between VS2010 and VS2012; EDMX file in Visual Studio 2010/2012