✅ Layered architecture EF Core error when creating migrations
I have a Web Api project which is using .NET Core 7, my layers are DAL, Services Entities and API. I recently moved connection string to appsettings.json file (it was hardcoded in my appdbcondext class before) and created a extension method in DAL layer which sets connection string, I am using this in my startup project (API) program.cs but when I run
dotnet ef migrations add testMig
it gives an error
It was not happening when I hard code connection string in DAL layer and add/update migrations,
ApplicationDbContext.cs (DAL)
DataAccessExtension.cs (DAL)
Program.cs (API Layer)
6 Replies
when you run
dotnet ef migrations ...
you need to specify the EF project and the startup project.
Usually:
I have tried that but I get different error which says I tried installing EFCore and Design in my API project but nothing changes
yea the API needs the EFCore Design packages. Can you share the csproj file of your API?
Oddly after restarting the Visual Studio add migration worked
Another question, is it okay to have ef core packages installed both dal and api layer?
yeah it's necessary unfortunately
Oh alright then, I assume problem solved for now. Thanks for helping 😅