EntityTypeBuilder does not contain a definition for ToTable in EF Core

前端 未结 12 1473
南笙
南笙 2021-02-06 20:22

I have this sample code:

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Models;

namespace MySampleNamespace
{         


        
12条回答
  •  死守一世寂寞
    2021-02-06 20:47

    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);
    

提交回复
热议问题