question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add inheritdoc to migration files

See original GitHub issue

It would be nice if dotnet ef migrations add would automatically add

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member

to the beginning of generated file and

#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member

at the end of file. I mean both (migrations and designer).

For example:

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member

using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;

namespace OpPIS.Web.Hosting.Migrations
{
    public partial class Fix5 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<int>(
                name: "ParentAnchorX",
                table: "VarDesign_Parameter-ImageManipulations",
                nullable: true);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "ParentAnchorX",
                table: "VarDesign_Parameter-ImageManipulations");
        }
    }
}

#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

9reactions
ajcvickerscommented, Jan 12, 2018

@MaklaCof We will have a think about adding XML comments to the generated code, but we don’t plan to do it at the present time. Beyond that, we don’t want to generate this pragma all the time because most people will not need it. However, there is a similar discussion about auto-generated in issue #10203. I posted a code snippet in that issue showing how to override the generator to add a line–this should also work for the pragma.

5reactions
bobvandevijvercommented, Oct 31, 2018

For reference in this ticket, this is what I used to generate the pragma’s:

public class FooMigrationsGenerator : CSharpMigrationsGenerator
{
    private const string PragmaWarningDisable = @"#pragma warning disable 1591";
    private const string PragmaWarningRestore = @"#pragma warning restore 1591";

    public FooMigrationsGenerator(
        MigrationsCodeGeneratorDependencies dependencies, CSharpMigrationsGeneratorDependencies csharpDependencies)
        : base(dependencies, csharpDependencies)
    {
    }

    public override string GenerateMigration(string migrationNamespace, string migrationName,
                                             IReadOnlyList<MigrationOperation> upOperations,
                                             IReadOnlyList<MigrationOperation> downOperations)
    {
        return PragmaWarningDisable
               + Environment.NewLine
               + base.GenerateMigration(migrationNamespace, migrationName, upOperations, downOperations)
               + Environment.NewLine
               + PragmaWarningRestore
               + Environment.NewLine;
    }

    public override string GenerateMetadata(string migrationNamespace, Type contextType, string migrationName,
                                            string migrationId, IModel targetModel)
        => PragmaWarningDisable
           + Environment.NewLine
           + base.GenerateMetadata(migrationNamespace, contextType, migrationName, migrationId, targetModel)
           + Environment.NewLine
           + PragmaWarningRestore
           + Environment.NewLine;
}

Together with this class somewhere in the starting assembly:

public class DesignTimeServices : IDesignTimeServices
{
    /// <inheritdoc />
    public void ConfigureDesignTimeServices(IServiceCollection services)
    {
        // Register custom migration generator which adds a pragma disable for xml-comments
        services.AddSingleton<IMigrationsCodeGenerator, FooMigrationsGenerator>();
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Entity Framework Migration Inheritance without creating the ...
I have database objects that all inherit from a parent class with some base properties. Base Entity public abstract class Entity : IAuditable...
Read more >
Migrations | Django documentation
Migrations are Django's way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema....
Read more >
How to Use EF Core Migrations - C# Tutorial
Use EF Core migration flow to apply changes from models to the database. · Use the Add-Migration command to create a new migration....
Read more >
Using the <inheritdoc /> Tag
This allows you to inherit documentation from base class libraries without having to add them as documentation assemblies in your project. Since the...
Read more >
Migrations - Flyway
Migrations. Overview. With Flyway all changes to the database are called migrations. Migrations can be either versioned or repeatable.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found