In my solution I want to use Asp.net core + EF Code first
I have 2 projects:
In CC.API I have startup class and there is:
services.AddDbContext<DataContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), b => b.MigrationsAssembly("CC.Infrastructure")));
(Connection string is in appsettings.json)
As you can see I'm trying to keep migration files in different project - CC.Infrastructure.
Unfortunately whilst Add-Migration Init
I receives an error:
Your target project 'PK.API' doesn't match your migrations assembly 'PK.Infrastructure'. Either change your target project or change your migrations assembly
If I will change in startup b => b.MigrationsAssembly("CC.API")
then everthing works fine, but files migration files will be in CC.API :/
This is/was a longstanding issue with EF Core. The solution used to be making your class library an executable (temporarily) and then run all EF operations against it.
With current tooling, you can just run Add-Migration
while in the library folder; the only caveat is you need to set the startup-project
flag to the actual executable's project.
So the command ends up being something like:
C:\CC.Infrastructure>dotnet ef migrations add NewMigration --startup-project ../CC.API/CC.API.csproj
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With