Fluent NHIbernate 忽略重写 Id 属性上的列名称
我有一个继承 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
映射覆盖仅针对确切类型执行,而不针对映射覆盖中类型的子类类型执行。您必须为子类指定覆盖。
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.