Efcore: Can Scaffold-DbContext generate entities with comments

Created on 29 Nov 2019  路  16Comments  路  Source: dotnet/efcore

Bring comments and swagger output interface more intuitive

area-scaffolding closed-fixed community-contribution customer-reported type-enhancement

All 16 comments

Implemented for SQL Server in 3.0

@netnr Are you asking for comments from the database to be converted to C# comments on entity types? For example:

C# /// <summary> /// This came from the database... /// </summary> public class Blog { ... }

@ajcvickers Yes

@netnr This is something that we would support as part of #4038. However, external tools such as those from @ErikEJ and @tonysneed may already support this through their templating mechanisms.

@netnr Here is my scaffolding library: https://github.com/TrackableEntities/EntityFrameworkCore.Scaffolding.Handlebars. EF Core Power Tools by @ErikEJ also include my scaffolding library.

@ajcvickers Any particular reason why this could not simply be in the product?
see https://github.com/ErikEJ/EFCorePowerTools/pull/372/files for needed changes.

@ErikEJ Do you really feel people want this behavior by default? /cc @bricelam @JeremyLikness

Not 100% sure, I am making it the default for now in the daily build, but fail to see why it would be an issue.

FWIW, EF Reverse POCO template has it enabled by default, and I cannot find any complaints about it. https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/blob/master/EntityFramework.Reverse.POCO.Generator/Database%20NorthwindSqlCe40.tt#L84 - but then again I just found out who made it the default: https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/issues/16 馃槅

I also saw this: https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/commit/41a7eaa248de1afc8d6bd3567df2f774cd47571d

@ErikEJ Let's circle back round after it's been the default for a month or two. If there are still no complaints, then we should consider it.

@ajcvickers Sounds good, I will do a release to MarketPlace soon then.

@ajcvickers Power Tools with comments on by default has been released since May 2020, and I have not had a single complaint - except about bugs in my implementation 馃槅

This is what I currently have:

        private void WriteComment(string comment)
        {
            if (!string.IsNullOrWhiteSpace(comment))
            {
                _sb.AppendLine("/// <summary>");

                foreach (var line in comment.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None))
                {
                    _sb.AppendLine($"/// {System.Security.SecurityElement.Escape(line)}");
                }

                _sb.AppendLine("/// </summary>");
            }
        }

Thanks for the update, @ErikEJ.

I do this in my T4 templates by default too. Looking at Erik's code, I have a few bugs to fix... 馃槵

@bricelam yeah, that was also my initial implementation, until I faced some real life comments

Are you planning to enable this in EF Core 6 ? (I could do a PR)

I think we'd happily accept a PR for 6.0

Was this page helpful?
0 / 5 - 0 ratings