0

I need to map the following class hierarchy using 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
}

Thanks

SharePoint Newbie
  • 5,974
  • 12
  • 62
  • 103
  • This is called "polymorphic relationships", a pattern that can be accommodated by [various data models](http://stackoverflow.com/questions/8895806/how-to-implement-polymorphic-associations-in-an-existing-database). – Gert Arnold Mar 13 '12 at 20:19

1 Answers1

0

It is not possible. Each entity can be mapped only once. It would require you to involve some inheritance in Rule and Parameter classes but at the end your Entity1 and Entity2 will need to reference derived rule to set correct structure.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670