nHibernate 3 - 左连接重新Linq解决方案

Jam*_*mes 11 linq nhibernate left-join

我试图用nHibernate 3运行下面的Linq查询.

var items = from c in session.Query<tbla>()
       join t in session.Query<tblb>() on c.Id equals t.SomeId into t1 // use left join on trades.
       from t2 in t1.DefaultIfEmpty()
select new {item = c, desc = t2.Description};
Run Code Online (Sandbox Code Playgroud)

根据我的知识,这是在linq中执行左连接的库存方式.但它给了我一个不受支持的异常消息.如何在不诉诸HQL的情况下实现基本的左连接?这似乎有些愚蠢,因为像nHibernate一样普遍存在的ORM不能支持像左连接这样的行人.

[编辑]

我在下面给出了我自己问题的真实答案.

Jam*_*mes 8

经过进一步的研究; 使用QueryOver以强类型方式实现这一点是可能的(尽管不是很明显).诀窍是将外部Query别名变量与WithAlias和TransformUsing结合使用.这是一个使用过滤和排序进行连接的示例.

// Query alias variables 
entityTypeA anchorType = null;
entityTypeB joinedType = null;

var items = session.Query<entityTypeA>( ()=>anchorType )
            .Left.JoinAlias(() => anchorType.FieldName, () => joinedType)
            .WithSubquery.WhereProperty(e => e.FieldD).In(myFilterList)
            // bind property mappings using WithAlias
            .SelectList(list => list
                        .Select(e => e.FieldNameA).WithAlias( ()=> anchorType.FieldNameA )
                        .Select(e => e.FieldNameB).WithAlias( ()=> anchorType.FieldNameB )
                        )
           .OrderBy(e => joinedType.FieldNameC).Desc
           .TransformUsing(Transformers.AliasToBean<entityTypeA>()) // transform result to desired type.
           .List<entityTypeA>();
Run Code Online (Sandbox Code Playgroud)