简体   繁体   English

在使用Model-First方法时,如何将XML注释添加到Entity Framework生成的自动生成的类中?

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

I have added information into the Documentation.Summary property in the graphical editor but that's not being added to the generated classes. 我已将信息添加到图形编辑器中的Documentation.Summary属性中,但未将其添加到生成的类中。 Is there any way to do this? 有没有办法做到这一点?

I found the answer to this was to alter the T4 template (.tt file in solution). 我发现答案是改变T4模板(解决方案中的.tt文件)。 This is responsible for generating the C# class code. 这负责生成C#类代码。 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)#>
<#
    }
}
#>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM