Customize the DbContext Generator

2019-06-25 13:42发布

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条回答
放我归山
2楼-- · 2019-06-25 14:27

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:

查看更多
登录 后发表回答