使用Code First和多个继承级别 [英] Using Code First with Multiple Inheritance Levels

查看:63
本文介绍了使用Code First和多个继承级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Code First设置多级继承模型?


假设我有以下类:


LiabilityRate和PropertyRate都继承了具有TPT模型的Rate。


但是我有了
BuildingRate和ContentsRate继承自PropertyRate并带有TPH模型地点,基于名为RateType的PropertyRate表上的列进行区分。


 


这个想法在我脑海里起作用,我就是不能似乎让它与Code First一起工作没有错误。  我的课程如下所示:


 


 
public abstract < span style ="color:Blue;"> class 评分
{
[Key]
public int ID { get ; set ; }

public DateTime EffectiveDate { get ; set ; }
public DateTime? EndDate { get ; set ; }
}

public class PropertyRate:Rate
{
public int TerritoryID {获得; set ; }
public int ProgramID {获得; set ; }
}

public class LiabilityRate:Rate
{
public int TerritoryID {获得; set ; }
}

public class BuildingRate:PropertyRate
{
public decimal Frame14 {获得; set ; }
public decimal Frame58 {获得; set ; }
}

public class ContentsRate:PropertyRate
{
public decimal Frame14 {获得; set ; }
public decimal Frame58 {获得; set ; }
}

解决方案

嗨杰夫,


CTP5在混合映射方案中有很多错误,所以它确实不起作用。然而,我们将很快发布一个候选版本,它在混合映射方面更加稳定,并支持这种情况。


有关即将发布的版本的信息在这里;  http:// blogs .msdn.com / b / adonet / archive / 2011/03/02 / ef-4-1-is-coming-dbcontext-api-amp-code-first-rtw.aspx


〜罗文


Is it possible to have a multi-level inheritance model set up with Code First?

Say I have the following classes:

LiabilityRate and PropertyRate both inheriting from Rate with a TPT Model in place.

But then I have
BuildingRate and ContentsRate inheriting from PropertyRate with a TPH Model in place, discriminated based on a column on the PropertyRate table called RateType.

 

The idea works in my head, I just can't seem to get it to work with Code First without errors.  My classes look like this:

 

  public abstract class Rate
  {
    [Key]
    public int ID { get; set; }

    public DateTime EffectiveDate { get; set; }
    public DateTime? EndDate { get; set; }
  }

  public class PropertyRate : Rate
  {
    public int TerritoryID { get; set; }
    public int ProgramID { get; set; }
  }

  public class LiabilityRate : Rate
  {
    public int TerritoryID { get; set; }
  }

  public class BuildingRate : PropertyRate
  {
    public decimal Frame14 { get; set; }
    public decimal Frame58 { get; set; }
  }

  public class ContentsRate : PropertyRate
  {
    public decimal Frame14 { get; set; }
    public decimal Frame58 { get; set; }
  }

解决方案

Hi Jeff,

CTP5 has a lot of bugs around hybrid mapping scenarios, so it really doesn't work. However we will shortly be releasing a Release Candidate which is a lot more stable around hybrid mapping and does support this scenario.

Info about the upcoming releases is here; http://blogs.msdn.com/b/adonet/archive/2011/03/02/ef-4-1-is-coming-dbcontext-api-amp-code-first-rtw.aspx

~Rowan


这篇关于使用Code First和多个继承级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆