Is ObjectContext deprecated in .NET 4.5?

.net entity-framework

Question

I've been using ObjectContexts for quite a long time now. Now that I've installed VS 2012, for my surprise the Entity Data Model does not have an option for a Code Generation Item that creates ObjectContexts and EntityObjects instead of DbContexts and POCOs.

Is it deprecated now? I see the ObjectContext class is still available, but there's no way I can use it as the output of my EDMXs.

1
14
11/28/2012 4:38:42 PM

Accepted Answer

ObjectContext is not deprecated. Actually DbContext is just a layer on top of ObjectContext. DbContext API has much nicer/smaller API and is easier to work with. Also POCO entities are much cleaner. This was the reason to change code generation. If you still want to use ObjectContext and EntityObject based entities remove *.tt files under the *.edmx file. Double click the edmx file to open it in the designer. Click on the designer surface. In the properties change "Code Generation Strategy" from "None" to "Default".

EDIT

The behavior has changed a bit in the EF6 designer that ships with VS2013 (and is available for download for VS2012). If you are using EF5 the two options are: 'T4' and 'LegacyObjectContext'. If you are using EF6 the dropdown is disabled. If you would like to use ObjectContext in an EF6 app you need to use Entity Object generator for EF6 (note this link points just to one version of the template but there are actually a few versions depending on what you need - C# vs. VB.NET, WebSite non-WebSite - here is the list). You can find more details about changes in the EF6 tooling here.

19
1/6/2014 9:26:45 PM

Popular Answer

Microsoft recommends the EF5.x DbContext Generator for new projects. It is the default template in VS2012. PreVS2012 users can find it using the ExtensionManager (search for EF5.x) or download it here.

You can of course still generate EntityObjects and ObjectContext by using the EF4.x EntityObject Generatortemplate which can be found here.

How to set things up is described here.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow