映射继承的实体

发布于 2024-10-27 05:19:55 字数 739 浏览 1 评论 0原文

我使用 Fluent Nhibernate(很高兴),但在映射某些实体时遇到一些麻烦:

  public enum AdverticeType { None,Image,Flash,Script}      

  public class Advertice      
  {
      public virtual int ID { get;set;}
      public virtual string Name { get;set;}
      public virtual AdverticeType AdverticeType  { get;set;}
  }

  public class ImageAdvertice : Advertice
  {
       public virtual int ID { get;set;}
       public virtual string Path { get;set;}
       public virtual string URL { get;set;}
  }

  public class ScriptAdvertice : Advertice
  {
       public virtual int ID { get;set;}
       public virtual string Code { get;set;}
  }

How do i map toEntity so the ID in ScriptAdvertice is generated by ID in Advertice.

Im using Fluent Nhibernate(with pleasure) but have some trouble mapping some entities:

  public enum AdverticeType { None,Image,Flash,Script}      

  public class Advertice      
  {
      public virtual int ID { get;set;}
      public virtual string Name { get;set;}
      public virtual AdverticeType AdverticeType  { get;set;}
  }

  public class ImageAdvertice : Advertice
  {
       public virtual int ID { get;set;}
       public virtual string Path { get;set;}
       public virtual string URL { get;set;}
  }

  public class ScriptAdvertice : Advertice
  {
       public virtual int ID { get;set;}
       public virtual string Code { get;set;}
  }

How do i map to entities so the ID in ScriptAdvertice is generated by ID in Advertice.

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

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

发布评论

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

评论(1

↙厌世 2024-11-03 05:19:55

使用 ClassMap 映射 Advertice,使用 SubclassMap 映射 ImageAdverticeScriptAdvertice

例如

public class AdverticeMap : ClassMap<Advertice>
{
  public AdverticeMap()
  {
    Id(x => x.ID);
  }
}

public class ImageAdverticeMap : SubclassMap<ImageAdvertice>
{
  public ImageAdverticeMap()
  {}
}

public class ScriptAdverticeMap : SubclassMap<ScriptAdvertice>
{
  public ScriptAdverticeMap()
  {}
}

Map Advertice using a ClassMap, and ImageAdvertice and ScriptAdvertice using a SubclassMap.

e.g.

public class AdverticeMap : ClassMap<Advertice>
{
  public AdverticeMap()
  {
    Id(x => x.ID);
  }
}

public class ImageAdverticeMap : SubclassMap<ImageAdvertice>
{
  public ImageAdverticeMap()
  {}
}

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