Fluent Nhibernate Composite Key does not create connections for reference objects

I have a composite key mapping as shown below:

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

This works great for simple get and inserts, however it does not create joins with the tables mentioned in the link where I try to use them as part of a query.

So this is:

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

Creates 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;
+2
source share
1 answer

I had exactly the same problem. Adding link mapping helped, but the problem makes no sense:

Try the following:

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

All Articles