Fluent Nhibernate Composite Key Not Generating Joins For Referenced Entities

匿名 (未验证) 提交于 2019-12-03 07:50:05

问题:

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.

So this:

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

Generates the following 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;

回答1:

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

Try this:

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


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!