首页 > 解决方案 > 在 EF Core 3.1 中替换 Map() 的最佳方法是什么

问题描述

我已经将EntityFramework 6的项目实现到EntityFramework Core 3.1中。使用 Roslyn API,我必须将实体映射到实体框架中的表。我对此一无所知。

示例.cs

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
   modelBuilder.Entity<Student>().Map(m =>
   {
      m.Properties(p => new { p.StudentId, p.StudentName});
      m.ToTable("StudentInfo");
      }).Map(m => {
             m.Properties(p => new 
                     { p.StudentId, p.Height, p.Weight, p.Photo, p.DateOfBirth});
            m.ToTable("StudentInfoDetail");
    });
  modelBuilder.Entity<Standard>().ToTable("StandardInfo");
}

建议基于堆栈溢出链接,EF 核心不再支持。参考:EF Core 2.0 中的一个实体 2 表

请就此提出替代解决方案以及如何在 Roslyn API 中执行建议?  

标签: c#entity-framework-coreentity-framework-6roslynroslyn-code-analysis

解决方案


推荐阅读