mapping multiple tables to a single entity class in entity framework

前端 未结 1 1139
挽巷
挽巷 2020-12-01 05:33

Before this is marked as a duplicate, I have checked the other related posts and they do not answer my question.

I am working on a legacy database that has 2 tables

相关标签:
1条回答
  • 2020-12-01 05:52

    You can use Entity Splitting to achieve this if you have the same primary key in both tables.

      modelBuilder.Entity<TestResult>()
        .Map(m =>
          {
            m.Properties(t => new { t.Name, t.Text, t.Units /*other props*/ });
            m.ToTable("Result");
          })
        .Map(m =>
          {
            m.Properties(t => new { t.Status, t.Analysis /*other props*/});
            m.ToTable("Test");
          });
    

    Here's a useful article

    0 讨论(0)
提交回复
热议问题