Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to implement code first approch without adding any references to web project?

I have added my dbContext in separate class library and added referce of this project to WebAPI project.
Now i want to create a migrations. But to create it i need to add some entity framework references into webapi project too.
this will violate SOP principle of my architechture.

So how can i implement code first approch where my web api is not dependent on DB layer?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It is not necessary for your webapi project to have a direct dependency on EntityFramework.

You can specify your database class library project to be the one which will hold the migrations. E.g:

dotnet ef migrations add MigrationName --project DatabaseClassLibrary --startup-project WebApiProject

The above command will use the WebApiProject as the startup-project as that will most likely (but not always) have the DI setup for creating an instance of your DbContext for your database provider.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading