Is ObjectContext deprecated in .NET 4.5?

后端 未结 3 2085
北海茫月
北海茫月 2021-02-05 14:36

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 Cod

3条回答
  •  -上瘾入骨i
    2021-02-05 14:48

    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.

提交回复
热议问题