How to add EF core migrations to .net core 2 class library?

.net-core-2.0 c# entity-framework entity-framework-core

Question

I created a .net core 2 class library. and I created the entities and entities type configurations. I created the DbContext

public class EFDBContext : DbContext
{
    public EFDBContext(DbContextOptions options) : base(options)
    {

    }
}

then I created a TemporaryDbContextFactory

public class TemporaryDbContextFactory : IDesignTimeDbContextFactory<EFDBContext>
{
    public EFDBContext CreateDbContext(string[] args)
    {
        var builder = new DbContextOptionsBuilder<EFDBContext>();
        builder.UseSqlServer("Name=AppConnectionString",
            optionsBuilder => optionsBuilder.MigrationsAssembly(typeof(EFDBContext).GetTypeInfo().Assembly.GetName().Name));
        return new EFDBContext(builder.Options);
    }
}

I'm trying to run Add-Migration but I got nothing. the migration is not created

So what am I missing here ??

1
2
11/30/2017 1:29:33 PM

Accepted Answer

Sounds like you're hitting issue #10298. Add the following to your *.csproj file:

<PropertyGroup>
  <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
</PropertyGroup>
7
11/30/2017 5:57:44 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow