开发者

Modify MVCScaffolding t4 template for DB First

I am looking to use MvcScaffolding for a website that I already have a database for.

I am using the repository switch when scaffolding to create a repository per entity and then editing the file to use the entities rather than the MvcScaffolding context, obviously if I re generate the files then this change will be overwritten and I will have to fix all 80+ repositories!

So I have created a custom repository template using

Scaffold CustomTemplate repository repository

which I am looking to edit so that the repositories are generated correctly. I know I need to edit this line

<#= contextName #> context = new <#= contextName #>();

but I can't find which variable I should repla开发者_运维技巧ce contextName with.

I know I could easily hard code the model name in the repository file which I am about to do but wondered if there is a better way to do this?

The reason for wanting a way to do it programmatically is for scenarios where more than 1 EF model is used in a project and scaffolding is used for both.

Thanks

OneShot


There's a DbContextType param for the scaffolders -

-DbContextType : Specify the name of the database context class that should be generated or updated. By default, we use the name Context, e.g., SoccerSiteContext.

Could you set that to be the name of the relevant model and avoid changing the template?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜