How do I add XML comments to the auto-generated classes produced by Entity Framework when using Model-First approach?

StackOverflow https://stackoverflow.com/questions/14142821

  •  12-01-2022
  •  | 
  •  

Question

I have added information into the Documentation.Summary property in the graphical editor but that's not being added to the generated classes. Is there any way to do this?

Was it helpful?

Solution

I found the answer to this was to alter the T4 template (.tt file in solution). This is responsible for generating the C# class code. Find any place where you want summary information added (such as before each simple property that is written out). So for example, here is the altered code for the simple properties:

<#
if (simpleProperties.Any()) {
    foreach (var edmProperty in simpleProperties) {
        if (edmProperty.Documentation != null) {
#>
    ///<summary><#=edmProperty.Documentation.Summary #></summary>
<#
        }
#>
    <#=codeStringGenerator.Property(edmProperty)#>
<#
    }
}
#>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top