如何停止实体框架同时生成ObjectContext和dbContext [英] How do I stop Entity Framework from generating BOTH ObjectContext and dbContext
问题描述
- Visual Studio 2012
- 在VS2012中创建的NEW Model.EDMX文件
- 从先前创建的EDMX中复制一些EDMX xml到新的
现在. EDMX(TT变换,自定义工具等)正在生成两个THb DbContext类(在Model.tt/Model.Context.tt文件下)和 ObjectContext类(通过Model.designer). cs文件).参见下图:
Now. The EDMX (TT transform, custom tool, whatever, etc.) is generating BOTH DbContext classes (under the Model.tt/Model.Context.tt files) and ObjectContext classes (via the Model.designer.cs file). See image below:
一切都可以正常运行,并且可以与DbContext一起使用(但很明显,只有当我在构建之前删除Designer.cs文件时才可以使用),但是Designer.cs及其基于ObjectContext的代码不断出现.如何停止这种行为?!
Everything builds fine and works with the DbContext (but obviously only if I delete the Designer.cs file just before building) but the Designer.cs - and its ObjectContext-based code - keeps reappearing. How do I stop this behavior?!
推荐答案
我没有找到如何阻止Designer.cs文件生成ObjectContext的方法,但是我确实弄清楚了如何制作它,以便它不会出现.没关系.只需将构建操作"设置为无",而不是编译"即可.
I didn't find out how to stop the Designer.cs file from generating the ObjectContext, but I did figure out how to make it so that it doesn't matter. Just set the Build Action to "None" instead of "Compile".
这篇关于如何停止实体框架同时生成ObjectContext和dbContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!