Ran*_*dom 2 c# t4 entity-framework xml-comments entity-framework-5
我的EDMX文件存在以下问题.
在其中我已经为属性和实体编写了一些文档,但是我的EF 5的t4模板并没有生成这些值.
我想要的结果应该是
public class Person
{
/// <summary>
/// Hello World Summary!!
/// </summary>
/// <remarks>
/// Hello World Remarks!!
/// </remarks>
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
但我只能得到
public class Person
{
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如果不是这样,我为什么还能在edmx文件中设置文档属性.
看来实体框架不会使用代码文档为您生成对象,我无法看到nuget的解决方案,这是一种耻辱.
您可以修改T4模板,为您完成此操作而不会有太多麻烦.为了帮助您入门,如果您为实体打开T4模板,并找到看起来像这样的行(关于第74行):
<#=codeStringGenerator.Property(edmProperty)#>
Run Code Online (Sandbox Code Playgroud)
然后将其更改为以下内容:
<# if (edmProperty != null && edmProperty.Documentation != null) {#>
/// <summary>
/// <#= edmProperty.Documentation.Summary #>
/// </summary>
/// <remarks>
/// <#= edmProperty.Documentation.LongDescription #>
/// </remarks>
<# } #>
<#=codeStringGenerator.Property(edmProperty)#>
Run Code Online (Sandbox Code Playgroud)
这将生成您的属性的文档.
而且如果你去看起来像这样的线(关于我的第28行):
<#=codeStringGenerator.EntityClassOpening(entity)#>
Run Code Online (Sandbox Code Playgroud)
然后将其更改为以下内容:
<# if (entity != null && entity.Documentation != null) {#>
/// <summary>
/// <#= entity.Documentation.Summary #>
/// </summary>
/// <remarks>
/// <#= entity.Documentation.LongDescription #>
/// </remarks>
<# } #>
<#=codeStringGenerator.EntityClassOpening(entity)#>
Run Code Online (Sandbox Code Playgroud)
这应该给你你的课文档.
可能还有其他一些需要更新的地方(比如复杂和导航属性),但它应该可以帮到你.
马特