EF core - Creating a migration for a database without a connection string and in another class library

只谈情不闲聊 提交于 2019-12-11 04:08:27

问题


I want to create a migration for a second and subsequent databases that's in a class library different from the project that uses it. There is a wrinkle. I will never know the connection string until a user logs in and I can get it from a catalog database (saas).

For the catalog database I used the solution from this site. That was fine - This database has its connection string in appsettings.json and can uses dependency injection.

The client databases are all going to be identical using the same migration. My problem is, I dont know how to create this initial migration from the Package Manager Console..

I did try to run this:

dotnet ef migrations add INITIAL --context APIcontext -s ../Jobsledger.API

and its given me the following error:

No database provider has been configured for this DbContext.

Which I expected.

Given that CodingBlast solution (above) to running migrations in a different class library requires a connection which I don't have and requires the database connection to be registered at startup...

..and given that this migration is to be used by every user database to be created how do I create it and of course use it?

来源:https://stackoverflow.com/questions/55980487/ef-core-creating-a-migration-for-a-database-without-a-connection-string-and-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!