修改 MVCScaffolding t4 模板为 DB First
我希望将 MvcScaffolding 用于我已经拥有数据库的网站。
我在搭建脚手架时使用存储库开关为每个实体创建一个存储库,然后编辑文件以使用实体而不是 MvcScaffolding 上下文,显然如果我重新生成文件,那么此更改将被覆盖,我将不得不修复所有 80 + 存储库!
因此,我创建了一个自定义存储库模板,
Scaffold CustomTemplate repository repository
我希望使用它进行编辑,以便正确生成存储库。我知道我需要编辑这一行
<#= contextName #> context = new <#= contextName #>();
,但我找不到应该替换 contextName
的变量。
我知道我可以轻松地在存储库文件中对模型名称进行硬编码,但我想知道是否有更好的方法来做到这一点?
想要一种以编程方式执行此操作的方法的原因是针对在项目中使用多个 EF 模型并且同时使用脚手架的场景。
谢谢
一击
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 replace 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
脚手架有一个
DbContextType
参数 -您能否将其设置为相关模型的名称并避免更改模板?
There's a
DbContextType
param for the scaffolders -Could you set that to be the name of the relevant model and avoid changing the template?