I have an NHibernate mapping file I want to convert to fluent. I'm stuck with this one particular case:
<many-to-one name="LastChildRevision" update="false" not-found="ignore" access="readonly" fetch="join">
<formula>(SELECT TOP(1) CHILD_REVISION.CHILD_REVISION_ID FROM CHILD_REVISION WHERE CHILD_REVISION.PARENT_ID = PARENT_ID ORDER BY CHILD_REVISION.REVISION_NUMBER DESC)</formula>
</many-to-one>
My class has:
public virtual IList<ChildRevision> ChildRevisions { get; set; }
public virtual ChildRevision LastChildRevision
{
get
{
return this.ChildRevisions.OrderBy(o => o.RevisionNumber).LastOrDefault();
}
}
How can I translate this to Fluent NHibernate? When I try this:
References(x => x.LastChildRevision)
.Formula("(SELECT TOP(1) CHILD_REVISION.CHILD_REVISION_ID FROM CHILD_REVISION WHERE CHILD_REVISION.PARENT_ID = PARENT_ID ORDER BY CHILD_REVISION.REVISION_NUMBER DESC)")
.Access
.ReadOnly()
.Fetch
.Join();
I get this:
Invalid column name 'LastChildRevision_id'.
Thanks!
I know I asked this question a long time ago, but I decided to revisit Fluent NHibernate, and here's what I came up with:
References(x => x.LastChildRevision)
.Column("PARENT_ID")
.Not.Insert()
.Not.Update()
.Access.ReadOnly()
.NotFound.Ignore()
.Cascade.None()
.Formula("(SELECT TOP(1) CHILD_REVISION.CHILD_REVISION_ID FROM CHILD_REVISION WHERE CHILD_REVISION.PARENT_ID = PARENT_ID ORDER BY CHILD_REVISION.REVISION_NUMBER DESC)");