I have an ASP.NET Core 3.1 Web API application using EF Core. This is the my configuration in the ConfigureServices
method of the Startup
class:
services.AddDbContext<ApplicationContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("AppConn")));
The above configuration tested and works for a SQL Server database.
Then I switched to using Sqlite after installing its package successfully.
services.AddDbContext<ApplicationContext>(options =>
options.UseSqlite("Data Source=sqlitedemo.db"));
But when I try to add the EF migration
add-migration initial -context ApplicationContext
I get this error:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Internal.SemanticVersionComparer' from assembly 'Microsoft.EntityFrameworkCore, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
{ Stack trace }
Exception has been thrown by the target of an invocation.
EF Core will then enable lazy loading for any navigation property that can be overridden--that is, it must be virtual and on a class that can be inherited from. For example, in the following entities, the Post. Blog and Blog. Posts navigation properties will be lazy-loaded.
Lazy loading means that the related data is transparently loaded from the database when the navigation property is accessed.
EF Core does not support the EDMX file format for models. The best option to port these models, is to generate a new code-based model from the database for your application.
Please update to your entity framework core nuget package to 3.1.10(or latest 5.0.0). It will solve your problem.
I had EF Core 5 package installed, but not Microsoft.EntityFrameworkCore.Design
and one package were implicitly referencing older version (Microsoft.EntityFrameworkCore.Design 3.0.0
).
Installing explicit dependency on Microsoft.EntityFrameworkCore.Design 5.x.x
resolved the issue for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With