Add XML documentation / comments to properties/fields in EF generated classes

若如初见. 提交于 2019-12-10 03:05:51

问题


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?


回答1:


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.




回答2:


No. You will have to modify your T4 template used to generate classes (or create new custom tool for class generation) to make these comments for you.




回答3:


The EF generated classes are all "partial" classes. So, define a new file with the same class skeleton structure, and define your comments on those.

Example:

The EF generated class (Model.designer.cs):

public partial class Student : EntityObject {... // bunch of generated code}

Your own file (ModelDocumentation.cs):

/// <summary> Student documentation... </summary>
public partial class Student {}


来源:https://stackoverflow.com/questions/7672627/add-xml-documentation-comments-to-properties-fields-in-ef-generated-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!