流利的Nhibernate复合键未为参考实体生成联接 [英] Fluent Nhibernate Composite Key Not Generating Joins For Referenced Entities

查看:78
本文介绍了流利的Nhibernate复合键未为参考实体生成联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有复合键的映射,如下所示:

I have a mapping with a composite key as below:

CompositeId()
            .KeyReference(x => x.CreatedBy, "member_key")
            .KeyReference(x => x.Box, "box_key");

这对于简单的获取和插入效果很好,但是它并没有生成与参考中提到的表的联接,我尝试将它们用作查询的一部分.

This works fine for simple gets and inserts, however it is not generating joins with the tables mentioned in the reference where I try and use them as part of a query.

所以这个:

return _sessionFactory.GetCurrentSession().QueryOver<BoxMember>()
            .Where(x => x.Box.Id == boxId)
            .Where(x => x.Member.DeletedDate == null)
            .Fetch(x => x.Box).Eager
            .Fetch(x => x.CreatedBy).Eager
            .List();

生成以下SQL:

    SELECT this_.member_key     as member1_5_0_,
       this_.box_key        as box2_5_0_
FROM   box_member this_
WHERE  this_.box_key = '2750e160-ba72-4a70-b554-9fd600e3cfd0' /* @p0 */
and    m1_.deleted_date is null;

推荐答案

我遇到了完全相同的问题.添加参考映射很有帮助,但是这个问题还是毫无意义:

I had exactly the same issue. Adding Reference mapping helped, but the issue makes no sense anyway:

尝试一下:

CompositeId() 
            .KeyReference(x => x.CreatedBy, "member_key") 
            .KeyReference(x => x.Box, "box_key"); 
Reference(x => x.CreatedBy);
Reference(x => x.Box);

这篇关于流利的Nhibernate复合键未为参考实体生成联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆