How do I create an entity data model for inherited generic types?

I don't know how I can get an existing entity structure based on the following classes (simplified) into a database using Entity Framework (EF is a limitation, 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?

+2


source to share


1 answer


EF does not support generic Entity types (which is similar to what you are doing).

Although we made the change in EF 4.0 (not Beta1), so you will be able to use a non-generic class that derives from a generic class as Entity.

Hope it helps anyway



Alex

Entity Framework Team

Entity Framework Tips

+2


source







All Articles