配方多对一

时间:2013-10-09 16:47:12

标签: fluent-nhibernate fluent-nhibernate-mapping

我有一个我希望转换为流利的NHibernate映射文件。我坚持这个特例:

<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>

我的班级有:

public virtual IList<ChildRevision> ChildRevisions { get; set; }

public virtual ChildRevision LastChildRevision
{
    get
    {
        return this.ChildRevisions.OrderBy(o => o.RevisionNumber).LastOrDefault();
    } 
}

如何将其翻译为Fluent NHibernate?当我尝试这个时:

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();

我明白了:

Invalid column name 'LastChildRevision_id'.

谢谢!

2 个答案:

答案 0 :(得分:2)

我知道很久以前我问了这个问题,但我决定重温Fluent NHibernate,这就是我提出的问题:

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)");

答案 1 :(得分:0)

你可能会遇到一个错误。尝试先清除列

References(x => x.LastChildRevision)
    .Columns.Clear()
    .Formula("(SELEC ...