Entity framework 如何为继承的泛型类型创建实体数据模型?

Entity framework 如何为继承的泛型类型创建实体数据模型?,entity-framework,ado.net-entity-data-model,Entity Framework,Ado.net Entity Data Model,我不知道如何使用Entity Framework(EF是一个约束,我必须使用它)将基于以下类(简化)的现有对象结构获取到数据库中 公共抽象类WahWahProperty { 公共字符串名称{get;set;} 公共抽象类型属性类型{get;} } // ---------------- 公共类WahWahProperty:WahWahProperty { 公共T值{get;set;} 公共覆盖类型PropertyType { 获取{return typeof(T);} } } // ------

我不知道如何使用Entity Framework(EF是一个约束,我必须使用它)将基于以下类(简化)的现有对象结构获取到数据库中

公共抽象类WahWahProperty
{
公共字符串名称{get;set;}
公共抽象类型属性类型{get;}
}
// ----------------
公共类WahWahProperty:WahWahProperty
{
公共T值{get;set;}
公共覆盖类型PropertyType
{
获取{return typeof(T);}
}
}
// ----------------
公共类Wahwah容器
{
公共列表子项{get{…};}
公共列表父项{get{…};}//允许多个“父项”
公共列表属性{get{…};}
//…这里还有一些道具。。。
}

有什么想法吗?

EF不支持通用实体类型(这似乎就是您正在做的)

虽然我们在EF 4.0中做了更改(不是在Beta1中),所以您可以使用从泛型类派生的非泛型类作为实体

不管怎样,希望这有帮助

亚历克斯

项目经理实体框架团队


这会出现在Beta 2中吗?你能告诉我更多关于那个的信息吗?是的,那是一件好事。我是推动在产品中实现这一功能的人之一,但目前还没有任何东西可以描述这一点。感谢Alex,期待着很快看到这一点,这可能有助于在关系方面的重复使用,比如泛化实体之间的关联(在应用程序中实现一对多)。
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 ...
}