如何为继承的泛型类型创建实体数据模型? [英] How to create an Entity Data Model for inherited generic types?

查看:148
本文介绍了如何为继承的泛型类型创建实体数据模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道我如何可以使用实体框架(EF是一个约束,我必须使用它),基于以下类(简化)获取现有的对象结构。

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

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

public class WahWahProperty< T> :WahWahProperty
{
public T Value {get;组;

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

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

public class WahWahContainer
{
public List< WahWahContainer>孩子{get {...}; }
public List< WahWahContainer>父母{get {...}; } // multipleParentsallowed
public List< WahWahProperty>属性{get {...}; }
// ...这里有更多的道具...
}

任何想法?

解决方案

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

尽管我们在EF 4.0中进行了更改(不是在Beta1中),因此您将能够使用从泛型类派生的非泛型类作为实体。 / p>

无论如何希望这有助于



Alex



程序实体框架团队



实体框架提示


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?

解决方案

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

这篇关于如何为继承的泛型类型创建实体数据模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆