Customize the DbContext Generator

为君一笑 提交于 2019-12-10 16:58:15

问题


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.

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.


回答1:


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.

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

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

And the files are:

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

For more information:

  • How to: Locate and Organize Project and Item Templates


来源:https://stackoverflow.com/questions/34666926/customize-the-dbcontext-generator

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