I have this sample code:
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Models;
namespace MySampleNamespace
{
Porting from EF6 to EFCore, we had this issue. Our cause was .HasKey
now returns a KeyBuilder
and the .ToTable
doesn't operate on it. So reversing that worked.
Ie. Was:
mp.HasKey(m => m.Id)
.ToTable("Table")
Became:
mp.ToTable("Table")
.HasKey(m => m.Id);
For net core 3.1, need to install these packages:
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Relational
I had this problem, but did not need to install:
Microsoft.EntityFrameworkCore.Relational
I simply exited VS 2017 and re-opened my solution. I had the following NuGet packages installed:
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Tools
And the following CLI Tool Reference:
Microsoft.EntityFrameworkCore.Tools.DotNet
Install
Microsoft.EntityFrameworkCore
, MicrosoftEntityFramworkCore.Tools
, and finally Microsoft.EntityFrameworkCore.SqlServer
For me, my issue was that I trying to call ToView() incorrectly.
I was doing:
modelBuilder.Query<Vendor>(entity =>
{
entity.Property(v => v.VendorId).HasColumnName("VendorID");
entity.Property(v => v.Name).HasColumnName("Vendor Name");
}).ToView("vwVendors");
instead of:
modelBuilder.Query<Vendor>(entity =>
{
entity.ToView("vwVendors");
entity.Property(v => v.VendorId).HasColumnName("VendorID");
entity.Property(v => v.Name).HasColumnName("Vendor Name");
});
It's also possible you have version discrepancies in your solution, so for example, if one of the projects in your dependency chain has a 3.1
version of EF Core
and another project has a 2.1
, then you will also see this error, and no matter what you install it won't work, instead make sure they are the same version in the entire solution.