EF core can't use any tooling
Running
dotnet ef migrations script --project=App.Database
Rusults in
21 Replies
Possibly related to https://github.com/dotnet/efcore/issues/32835
GitHub
Migrations add doesn't work with Microsoft.Extensions.Hosting · Iss...
Hi Folks, I am building a WinUI 3 app and want to use SQLite using ef core. When using the Microsoft.Extensions.Hosting package, the dotnet ef migrations add command doesn't give any errors but...
Check your DB context and especially connection string. There's something wrong with connection string either it's not accessible or not correct. Or something wrong with your Db Context class.
Hmm well the connection string works on normal run, what should I check with context?
Thanks for the help BTW
Show your code
you can show your code i.e db context
Just the context?
truncated OnModelCreating its just full of relationship mappings
You need to change the method like this:
then try
I still get Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[Sadie.Database.SadieContext]'
I think the issue is my entities are in a seperate assembly to where the DbContext gets registered in the ioc?
Can you show how you register your dbconfext to the service collection
Did you use .AddDbContext
Reddit
From the csharp community on Reddit: EF Core unable to migrate code...
Explore this post and more from the csharp community
@hime my code is in that Reddit post
Sorry but I am on mobile and I can’t copy it right now
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
yeah and everybody doesn't have reddit account as well
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
Something can be wrong in Program.cs as well where you're registering your context. I got this error when I wasn't getting the connection string in the Program.cs .
idk why they're not letting me in xD. I've account but seems like they've blocked for some reason
Hey the program.cs is on reddit too
I'll attach it here now 🙂
Program.cs:
ServerServiceCollection
In DatavaseServiceCollection:
seems okay. Are the other db commands working correctly or none of them are working ? Like adding migrations, updating the db etc.
If none of the ef tools command are working then you can log the connection string to the console and check if it's being passed correctly if you haven't already checked that.
well... I check that in the app
I'll dump it to be sure, also pretty sure its every tool
It does dump it but with warnings this time
Adding a
IDesignTimeDbContextFactory
has fixed ituse
IsNullOrWhitespace
, like what if string is not null but only contains whitespaces@Salman good point
All migrations do is make one table, I don't think its finding my models correctly.
Well another thing you can do is to try update/reinstall the packages make sure efcore is up to date, apparently the code looks good and don't have any problems as far as I see.