Using Entity Data Model in VS 2012

[亡魂溺海] 提交于 2019-12-13 00:40:50

问题


I have used Entity Data Model before with VS 2010, but now I am having trouble with VS 2012. First of all, now in 2012 Entity Data Model there are two new files with .tt extension. Also the Designer.cs file is empty and has a message how to enable the code generation, but when I do enable the code generation it says that the objects already exist.

I am also missing the CreateObjectSet();

 using (MyEntities entitiesContext = new MyEntities())
            {
                var entitySet = entitiesContext.CreateObjectSet<T>();

            }

Not sure why, but now the entitiesContext doesn't have the .CreateObjectSet();

I wonder if someone could clear up what is going on.


回答1:


The new Entity Data Model in VS 2012 by default uses T4 templates (.tt) files instead of former custom tool for code generation. The generated context is also based newer DbContext API instead of ObjectContext API used by Visual Studio 2010 (that is the reason why it doesn't have the method - the equivalent method in DbContext API is Set<T>). Both T4 and DbContext API are currently recommended approach for using EF.

I don't have VS 2012 on my current machine but what you can try is to delete both .tt and turn on the old generation as described in .Desinger.cs.



来源:https://stackoverflow.com/questions/12493656/using-entity-data-model-in-vs-2012

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!