When using Entity Framework Database First it can happen that the code generated by the edmx file causes Code Analysis errors. This happens due to the fact that the t4-template misses the GeneratedCode attribute. It is pretty easy to modify the template to contain the necessary attributes.
Modify the context template
- Add using System.CodeDom.Compiler; at the right position in the using directives
- Add [GeneratedCode(“EntityModelCodeGenerator”, “4.0.0.0”)] above the class declaration line
Modify the template of the model classes
- Find EntityClassOpening and modify to the return a string starting with the GeneratedCode attribute
- Find <#=codeStringGenerator.UsingDirectives(inHeader: false)#> and add below using System.CodeDom.Compiler;