Fluent NHIbernate ignoring column name on overrided Id property
-
26-10-2019 - |
Question
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
Solution
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow