自定义DbContext生成器 [英] Customize the DbContext Generator

查看:134
本文介绍了自定义DbContext生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于数据库首次设计,创建 EDMX 生成DbContext和poco模型 T4(.tt)模板文件。

我可以自定义 Model.tt 文件,使其生成POCO类与Pascal类的名称和属性名称, Pascal案例中的poco类文件名符合我代码其余部分的编码标准。

For a database first design, creating the EDMX generates the DbContext and the poco model T4 (.tt) template files.
I am successfully able to customize the Model.tt file to make it generate POCO classes with Pascal cased class names and property names and also the poco class file names in Pascal case which fits beter with with the coding standards of the rest of my code.

我正在尝试解决的问题是,我必须为每个$ $编辑 Model.tt 文件c $ c> EDMX 当我创建一个,而我试图看看是否有任何方式来自定义tt文件生成器并添加代码修改,以便在创建时自动实现pascalcasing规则一个 EDMX

我不知道这是否可行。请建议。

The issue I am trying to tackle is, I have to edit the Model.tt files for every EDMX when I create one, rather I am trying to see if there any way to customize the tt file generator and add the code modification to it so that the pascalcasing rule gets implemented automatically when creating an EDMX.
I am not sure if this is possible. Please suggest.

推荐答案

您可以为实体框架定制Visual Studio项目模板。然后使用添加新项目窗口添加到项目中的每个edmx,选择 ADO.NET实体数据模型,将使用修改的模板。

You can customize Visual Studio item templates for entity framework. Then each edmx that you add to the project using Add New Item window, choosing ADO.NET Entity Data Model, will use modified templates.

例如,对于 C#语言和语言环境 1033 EF6 ,模板存储在:

For example, for C# language and locale 1033 and EF6, The templates are stored at:

\VisualStudioInstallationPath\Common7\IDE\ItemTemplates\CSharp\Data\1033\DbCtxCSEF6

文件是:


  • CSharpDbContext.Context.tt

  • CSharpDbContext.Types.tt

  • CSharpDbContext.Context.tt
  • CSharpDbContext.Types.tt

有关详细信息:

  • How to: Locate and Organize Project and Item Templates

这篇关于自定义DbContext生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆