在EF生成的类中添加XML文档/注释到属性/字段 [英] Add XML documentation / comments to properties/fields in EF generated classes

查看:365
本文介绍了在EF生成的类中添加XML文档/注释到属性/字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



但是,在EF生成的课程中,这些在我重新生成模型的时候都会消失。



有另一种方法吗?

解决方案

如Ladislav在答案中所说,您需要修改T4模板,以便将注释包含在生成的代码中。这个答案是从这篇文章



首先,您需要在模型设计器的属性框中指定您的注释。在文档 - >长说明和摘要下。



然后在模板中,您可以在文档的上方添加以上属性:

 < #if(!ReferenceEquals(edmProperty.Documentation,null))
{
#>
///< summary>
///<#= edmProperty.Documentation.Summary#> - <#= edmProperty.Documentation.LongDescription#>
///< / summary>
<#}#>

这将在生成的代码中的属性上方创建一个摘要块。


i have the habbit to comment properties and classes with the standard XML documentation, what it means / what they do.

But in EF generated classes off course, these are all gone when i regenerate the model.

Is there another way to do this?

解决方案

As Ladislav stated in his answer, you need to modify the T4 template so the comments will be included in the generated code. This answer was taken from this article:

First of all you need to specify your comments in the properties boxes of the model designer. Under Documentation -> Long Description, and Summary.

Then in the template, you can for example add this above the property you want to document:

<#if (!ReferenceEquals(edmProperty.Documentation, null))
{
#>
/// <summary>
/// <#=edmProperty.Documentation.Summary#> – <#=edmProperty.Documentation.LongDescription#>
/// </summary>
<#}#>

This will create a summary block above your property in the generated code.

这篇关于在EF生成的类中添加XML文档/注释到属性/字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆