I just needed to map one property using formula, but it looks like the
formula statement isn't executed at all and I get DB exception for
nonexistent column (ChildrenCount) instead, because FNH always
includes column element in property mapping. I'm using NHibernate
3.0.0.1001 so maybe that's the problem - I wasn't able to find it out.
The entity I'm trying to map looks like this:
public class RegionTreeItemDTO
{
public long Id { get; set; }
public long ParentId { get; set; }
public string Code { get; set; }
public string Name { get; set; }
public int ChildrenCount { get; set; }
public bool HasChildren { get { return ChildrenCount > 0; } }
}
the FNH mapping class look like this:
public class RegionTreeItemDTOMap: DTOMapBase<RegionTreeItemDTO>
{
public RegionTreeItemDTOMap() : base("REGION")
{
Id(x => x.Id);
Map(x => x.ParentId, "PARENT_ID");
Map(x => x.Code);
Map(x => x.Name);
Map(x => x.ChildrenCount)
.Formula("(select count(1) from REGION x where x.PARENT_ID =
Id)");
}
}
and the generated property mapping for the field with formula is this:
<property name="ChildrenCount" formula="(select count(1) from
REGION x where x.PARENT_ID = Id)" type="System.Int32, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="ChildrenCount" />
</property>
The column element is causing the problems. I just tried to exclude
the FNH mapping class and replace it with HBM mapping file without the
"column" element and the mapping just become to work. So it looks like
NH does not expect to have column element when mapping using formula,
but FNH still generates the column element anyway.
Is this FNH (I'm using the 1.0 RTM) bug or is it a bug/incompatibility
with NH3 I'm using?
--
You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To post to this group, send email to
fluent-n...@googlegroups.com.
To unsubscribe from this group, send email to
fluent-nhibern...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/fluent-nhibernate?hl=en.