Is it possible to reference or rename an entity's table alias in a Fluent NHibernate Formula? I can usually use "this_" but that unfortunately does not seem to be consistent based on the number of other aliases NHibernate generates.
this.Map(x => x.IsLocked).Formula("CASE WHEN (SELECT COUNT(*) FROM dbo.Child c WHERE c.InboundDate >= BeginDate AND c.InboundDate < EndDate) > 0 THEN 1 ELSE 0 END");
This gets me by but I run into trouble when I need to match of identically named fields, (like "ID.")
this.Map(x => x.IsLocked).Formula("CASE WHEN (SELECT COUNT(*) FROM dbo.Child c WHERE c.ID = ID) > 0 THEN 1 ELSE 0 END");
Here, because ID
is a column in c
, c.ID = ID
will always evaluate to true. In most cases, I can change this to c.ID = this_.ID
to get by, but in some of my entities, NHibernate will not use this_
as an alias, but something like parent1_
.