Get DbContext for Entities

放肆的年华 提交于 2019-12-07 02:33:25

So I guess you are using default code generator provided by EDMX designer - it will use ObjectContext and heavy weight EntityObject based entities.

If you want to use DbContext you must:

  • Turn off that default code generation - in property window remove Custom Tool for EDMX file
  • Download and install DbContext T4 generator (you can get it directly from extension manager in Visual Studio)
  • In EF designer select Add Code Generation Item from context menu in the designer surface (not on entity)

Now EF will add two .tt files to your project - one will be responsible for creating a new class for every entity or complex type defined in your EDMX file and the second will be responsible for creating class derived from DbContext and exposing sets for all your entity types

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