Separate POCO Object classes and DBContext from Entity Framework 6 Model

可紊 提交于 2019-11-29 23:11:16
fremis

Absolute paths are not required. It looks like your relative path is not correct. I am using EF6.1 and I have the POCO classes in a separate project. This is how I got it to work in VS 2013.

  1. Created a Class Library Project and added an ADO.NET Entity Data Model. This project will contain the DB Context.
  2. Added a new EF6.x DbContext Generator item to the DBContext project.
  3. Created a new Class Library Project. This project will contain the POCO objects.
  4. Moved the [Project Name]Model.tt file from the DbContext project to the POCO project.
  5. Edited the [Project Name]Model.tt file. On line 5, I changed:
    const string inputFile = @"SampleModel.edmx";
    to:
    const string inputFile = @"..\DbContext\SampleModel.edmx";
  6. Added a reference in the DbContext project to the POCO project.

If you are using VS 2013, you can debug the template to see how your relative path is being resolved.

  1. Add a breakpoint to your .tt file.
  2. Right-click the .tt file in the Solution Explorer and select "Debug T4 Template".
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!