Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EntityFramework t4 template - XML documentation

I have the following problem with my EDMX file.

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.

My desired result should be

public class Person
{
    /// <summary>
    /// Hello World Summary!!
    /// </summary>
    /// <remarks>
    /// Hello World Remarks!!
    /// </remarks>
    public string Name { get; set; }
}

But I only get

public class Person
{
    public string Name { get; set; }
}

And if not for this, why would I else be able to set documentation properties in the edmx file.

like image 213
Rand Random Avatar asked Nov 23 '25 11:11

Rand Random


1 Answers

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.

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.

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

like image 73
Matt Whetton Avatar answered Nov 25 '25 04:11

Matt Whetton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!