Generate POCO classes in different project to the project with Entity Framework model

后端 未结 3 2058
梦毁少年i
梦毁少年i 2020-11-27 03:44

I\'m trying to use the Repository Pattern with EF4 using VS2010.

To this end I am using POCO code generation by right clicking on the entity model designer and click

3条回答
  •  清歌不尽
    2020-11-27 03:49

    Actually the T4 templates in EF 4.0 were designed with this scenario in mind :)

    There are 2 templates:

    • One for the Entities themselves (i.e. ModelName.tt)
    • One for the ObjectContext (i.e. ModelName.Context.tt)

    You should put the ModelName.tt file in you POCO project, and just change the template to point to the EDMX file in the persistence aware project.

    Sounds weird I know: There is now a dependency, but it is at T4 generation time, not at compile time! And that should be okay? Because the resulting POCO assembly is still completely persistence ignorant.

    See steps 5 & 6 of this: http://blogs.msdn.com/adonet/pages/walkthrough-poco-template-for-the-entity-framework.aspx for more.

    Hope this helps

    Alex

提交回复
热议问题