Generate repositories from EF Code First with created DbContext model classes

不问归期 提交于 2019-12-12 17:41:17

问题


I'm starting a new project and want to use EF Code First pattern but I also want to use the repository pattern. I have been looking for a way to generate the repositories from the dbcontext models but all answers I've seen so far are for generating repositories from .edmx or DB. I don't want to create an .edmx.

The steps I want to do is this:
1. Write models
2. Generate repositories using t4 templates
3. Write app code from models and repos 4. Run Add-Migration to add migration code
5. Run update-database to update based off migration code

What could I use to tell it to generate t4 templates based on the model classes?


回答1:


I've found how to do it now. Using T4Scaffolding, I am going to be able to generate the repositories as I need. It also allows me to override the default t4 templates and create custom scaffolds too.




回答2:


There is a NuGet package I created which does this as well, it requires a namespace your models not a edmx file:

https://www.nuget.org/packages/RepositoryGenerator/



来源:https://stackoverflow.com/questions/11613268/generate-repositories-from-ef-code-first-with-created-dbcontext-model-classes

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