Reputation: 973
I have a c# class libary that has its own database context and Entity Framework migrations.
My solution contains a web site that references the class library as a Project Reference.
I can apply the EF migrations for the Class Library in Visual Studio from Package Manager Console by setting the default project to my Class Library and using the following command:
update-database -StartupProject MyMainWebProj -Context MyClassLibDbContext
I have created a private NuGet package for the class libary and updated the Web Site to reference the NuGet package rather than a project reference.
I cannot figure out how to run the EF migrations now that the class library is referenced via NuGet package.
Upvotes: 0
Views: 1721
Reputation: 183
You may use the builder object of the Use*() method during service configuration like mentioned here: https://github.com/jasontaylordev/CleanArchitecture/blob/d0f133ee026aec5cd5856c5592c307b5f20fa8e4/src/Infrastructure/DependencyInjection.cs#L28
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
configuration.GetConnectionString("DefaultConnection"),
b => b.MigrationsAssembly(typeof(SomeClassInTheOtherAssembly).Assembly.FullName)));
Upvotes: 2