I built a console project and use code first to map model to database. When I run the command of Add-Migration InitialMigration
, I get an error:
Method 'Create' in type 'Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServerSqlTranslatingExpressionVisitorFactory' from assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=3.1.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.
The DbContext
is:
class ActorDbContext : DbContext
{
public DbSet<Actor> Actors { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(
@"Server=(localdb)\mssqllocaldb;Database=ActorDb;"
+ "Trusted_Connection=True;");
}
}
The entity is:
public class Actor
{
public int Id { get; set; }
public String Name { get; set; }
public int Age { get; set; }
public bool AcademyWinner { get; set; }
}
You must include all the following packages to be of same version:
Microsoft.EntityFrameworkCore
Microsoft.AspNetCore.Identity.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.SqlServer
I tried it and it run well.
I just ran into this same issue using VS for Mac
.
My problem was I had the following versions of packages installed:
- Microsoft.EntityFrameworkCore.Tools
5.0.0-preview.8.20407.4
- Microsoft.EntityFrameworkCore.Design
5.0.0-preview.8.20407.4
- Microsoft.EntityFrameworkCore.SqlServer
3.1.8
Take note of the different versions used.
To correct the issue I uninstalled the preview
versions of the packages and installed the latest stable versions.
- Microsoft.EntityFrameworkCore.Tools
3.1.8
- Microsoft.EntityFrameworkCore.Design
3.1.8
- Microsoft.EntityFrameworkCore.SqlServer
3.1.8
Again take note of the versions for all 3 packages.
Once I had installed the correct version of each package the issue was resolved and my Add-Migration
worked.
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