Fluent NHIbernate 忽略重写 Id 属性上的列名称

发布于 2025-01-06 10:07:56 字数 719 浏览 1 评论 0原文

我有一个继承 Sharp Arch 实体类的抽象基类:

  /// <summary>
  /// defines an entity that will ne indexed by a search crawler and offered up as full-text searchable
  /// </summary>
  public abstract class IndexedEntity : Entity
  {
    [DocumentId]
    public override int Id
    {
      get { return base.Id; }
      protected set { base.Id = value; }
    }
  }

这是一个遗留数据库,实际上 Id 列被称为“HelpPageID”,所以我有一些映射覆盖:

mapping.Id(x => x.Id, "HelpPageID");

用于查询 HelpPage 当我简单地继承 Entity 时,效果很好。但是继承IndexedEntity,翻译成sql时,列名覆盖会被忽略,而是使用Id作为列,从而失败。

编辑 似乎覆盖是一个普遍问题,因为将覆盖直接放在类中具有相同的净效果

I have an abstract base class which inherits Sharp Arch's Entity class:

  /// <summary>
  /// defines an entity that will ne indexed by a search crawler and offered up as full-text searchable
  /// </summary>
  public abstract class IndexedEntity : Entity
  {
    [DocumentId]
    public override int Id
    {
      get { return base.Id; }
      protected set { base.Id = value; }
    }
  }

This is to a legacy db and actually the Id column is called "HelpPageID", so I have some mapping override as:

mapping.Id(x => x.Id, "HelpPageID");

The generated sql for querying HelpPage works fine when I simply inherit Entity. But inheriting IndexedEntity, when translated to sql, the column name override is ignored and instead Id is used for the column, thus failing.

Edit
Seems a general issue with an override as placing the override directly in the class has the same net effect

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

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

发布评论

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

评论(1

少年亿悲伤 2025-01-13 10:07:56

映射覆盖仅针对确切类型执行,而不针对映射覆盖中类型的子类类型执行。您必须为子类指定覆盖。

mapping overrides are only executed for the exact type not types which subclass the type in the mappingoverride. you have to specify an override for the subclass.

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