2012-03-13 23 views
0

我需要使用Entity Framework 4.3來映射下面的類層次結構。如果在Entity Framework 4.3中的不同實體下出現同一個子實體,它將如何映射到不同的表中?

public abstract class Rule 
{ 
    public long Id {get;set;} 
    public abstract ICollection<Parameter> Parameters {get;set;} 
} 

public class Entity1 
{ 
    public long Id {get;set;} 
    public ICollection<Rule> Rules {get;set;} 
    // Map Rule to table Entity1Rules and  
    // Parameters to table Entity1RuleParameters 
} 

public class Entity2 
{ 
    public long Id {get;set;} 
    public ICollection<Rule> Rules {get;set;} 
    // Map Rule to table Entity2Rules and  
    // Parameters to table Entity2RuleParameters 
} 

感謝

+0

這被稱爲「多態關係」,這是一種可以被[各種數據模型]所適應的模式(http://stackoverflow.com/questions/8895806/how-to-implement-polymorphic-associations-in-an-現有的數據庫)。 – 2012-03-13 20:19:36

回答

0

這是不可能的。每個實體只能映射一次。這將需要您在RuleParameter類中涉及一些繼承,但最後您的Entity1Entity2需要引用派生規則以設置正確的結構。

相關問題