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

发布于 2024-08-07 00:01:16 字数 711 浏览 7 评论 0原文

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

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 ...
}

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋千易 2024-08-14 00:01:16

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

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

无论如何,希望这对

Alex

项目经理实体框架团队

有帮助实体框架技巧

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文