How to create an Entity Data Model for inherited g

2019-04-13 01:40发布

I have no clue how i can get an existing object structure based on the following classes (simplified) into a database using Entity Framework (EF is a constraint, i have to use it).

public abstract class WahWahProperty
{
  public string Name { get; set; }
  public abstract Type PropertyType { get; }
}

// ----------------

public class WahWahProperty<T> : WahWahProperty
{
  public T Value { get; set; }

  public override Type PropertyType
  {
    get { return typeof(T); }
  }
}

// ----------------

public class WahWahContainer
{
  public List<WahWahContainer> Children { get {...}; }
  public List<WahWahContainer> Parents { get {...}; } // multiple "Parents" allowed
  public List<WahWahProperty> Properties { get {...}; }
  //... some more props here ...
}

Any ideas?

1条回答
啃猪蹄的小仙女
2楼-- · 2019-04-13 02:31

The EF doesn't support generic Entity types (which seems to be what you are doing).

Although we have made a change in EF 4.0 (not in Beta1) so you will be able to use a non-generic class derived from a generic class as an Entity.

Anyway hope this helps

Alex

Program Manager Entity Framework Team

Entity Framework Tips

查看更多
登录 后发表回答