替代EF Code中的MapHierarchy()第一个CTP 5

时间:2010-12-08 18:16:10

标签: c# entity-framework code-first entity-framework-ctp5

如何在新CTP中设置以下内容?

modelBuilder.Entity<RequestBase>()
                .MapHierarchy()
                .Case<RequestBase>(b => new { b.Id, b.Comment, Discriminator = 0 })
                .Case<Request1>(s => new { request1_Id = Column.Id,  Discriminator = 1 })
                .Case<Request2>(m => new { request2_Id = Mission.Id, m.Comment, m.Date, Discriminator = 2 })
                .ToTable("dbo.Requests");

1 个答案:

答案 0 :(得分:4)

这样的事情会起作用:

modelBuilder.Entity<RequestBase>()
            .Map<RequestBase>(r => r.Requires("Discriminator").HasValue(0))
            .Map<Request1>(r1 => r1.Requires("Discriminator").HasValue(1))
            .Map<Request2>(r2 => r2.Requires("Discriminator").HasValue(2))
            .ToTable("dbo.Requests");