EntityFramework-Reverse-POCO-Code-First-Generator icon indicating copy to clipboard operation
EntityFramework-Reverse-POCO-Code-First-Generator copied to clipboard

Add Support for EFCore Inheritance Workaround

Open weisso5 opened this issue 4 years ago • 1 comments

Hello,

Per the the existing EF tickets:

https://github.com/dotnet/efcore/issues/7533 https://github.com/dotnet/EntityFramework.Docs/issues/594

It would be great if the generator could support adding in the work around to the generated context in order to generate this example

Would potentially also require a change to: AddParameterlessConstructorToDbContext

This allows the generated context to work out of the box with DbContextPool and Inheritance.

Thanks.

weisso5 avatar May 05 '20 17:05 weisso5

Example link above contains:

I was able to resolve this without a hack by providing a protected constructor that uses DbContextOptions without any type. Making the second constructor protected ensures that it will not get used by DI.

public class MainDbContext : DbContext
{
    public MainDbContext(DbContextOptions<MainDbContext> options)
        : base(options)
    {
    }

    protected MainDbContext(DbContextOptions options)
        : base(options)
    {
    }
}

public class SubDbContext : MainDbContext
{
    public SubDbContext (DbContextOptions<SubDbContext> options)
        : base(options)
    {
    }
}

sjh37 avatar May 05 '20 18:05 sjh37