问题描述
我的EDMX文件有以下问题。
I have the following problem with my EDMX file.
在其中我已经为属性和实体编写了一些文档,但是我的t4模板EF 5不会生成这些值。
In it I have written some Documentation for the properties as well as the Entities, but the t4 template of my EF 5 doesnt generate those values.
我想要的结果应该是
public class Person
{
/// <summary>
/// Hello World Summary!!
/// </summary>
/// <remarks>
/// Hello World Remarks!!
/// </remarks>
public string Name { get; set; }
}
但是我只得到
public class Person
{
public string Name { get; set; }
}
如果不是这样,为什么我可以设置文档属性在edmx文件。
And if not for this, why would I else be able to set documentation properties in the edmx file.
推荐答案
看来,实体框架不会为您生成代码文档的对象,我无法看到nuget上的解决方案,这是一个耻辱。
It does appear that entity framework isn't going to generate the objects for you with code documentation, and I cant see a solution on nuget, which is a shame.
您可以修改T4模板,为您做到这一点,而不用太麻烦。要开始使用,如果您打开实体的T4模板,并找到这样的行(关于第74行):
You can modify the T4 template to do this for you without too much hassle. To Get you started, if you open the T4 template for your entities, and find the line that looks like this (about line 74 for me):
<#=codeStringGenerator.Property(edmProperty)#>
然后将其更改为如下所示:
Then change it to something like this:
<# if (edmProperty != null && edmProperty.Documentation != null) {#>
/// <summary>
/// <#= edmProperty.Documentation.Summary #>
/// </summary>
/// <remarks>
/// <#= edmProperty.Documentation.LongDescription #>
/// </remarks>
<# } #>
<#=codeStringGenerator.Property(edmProperty)#>
这将生成您的属性文档。
This will generate the documentation for your properties.
另外,如果你去看这样的行(关于第28行):
And also if you go to the line that looks like this (about line 28 for me):
<#=codeStringGenerator.EntityClassOpening(entity)#>
然后将其更改为如下所示:
Then change it to something like this:
<# if (entity != null && entity.Documentation != null) {#>
/// <summary>
/// <#= entity.Documentation.Summary #>
/// </summary>
/// <remarks>
/// <#= entity.Documentation.LongDescription #>
/// </remarks>
<# } #>
<#=codeStringGenerator.EntityClassOpening(entity)#>
这应该给你你的课程文档。
This should give you your class documentation.
可能还有其他几个需要更新的地方(如复杂和导航属性),但是最好的方法应该是你。
There's probably a few other places that will need updating (like complex and navigation properties), but it should get you most of the way.
Matt
这篇关于EntityFramework t4模板 - XML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!