Unable to create an object of type 'UnitOfWork'. [Answered]
Hello everyone. I have two projects; one is an API and the other is a DAL (Data Access Layer). I want the DbContext and the Migrations to live in the DAL. However, it seems I have to add migrations via the API project.
How can I create migrations in the DAL project?
22 Replies
are you using the
dotnet ef
commands, or the nuget package manager powershell commands like Add-Migration
?The second one.
This is the project structure if that helps.
okay, then you need to set your api project to your solution startup project
and then you set the dropdown in the nuget package manager window to your DAL project
I have multiple startup projects. Is that the issue? The API and Client should run at the same time.
dunno, may or may not work.
Oh haha that did work.
Can't believe it was so simple.
well, the ef tools need to know where to get your setup from (startup) and what your "target" project is 🙂
Yeah, I suppose it gets confused when you have multiple startup projects.
yup
that sounds likely
I don't know much about the internal workings of it.
but I know you don't usually have multiple startups.
you can specify the startup project with a command line option too, if you want
so you dont need to mess with the solution
I think its just
--startupProject
but not 100% sureOkay, maybe I just have to change the startup project each time I want to make a migration.
I imagine --startupProject would just do that for me once.
yep
or well, it would "set" it for the migration
but not change anything
Oh that's convenient.
Just temporarily then.
but you'd need to specify it each time you made a migration 😛
or
Update-Database
etcI need this for my project
so I guess I would have to do that.
I'll document it properly for other people working on it.
It can't find --startupProject. Would I have to do something like this?
try
-StartupProject API
i think the doubledash one is for dotnet ef
Hey that worked! Thank you very
✅ This post has been marked as answered!