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;
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);
来源:https://stackoverflow.com/questions/9682850/fluent-nhibernate-composite-key-not-generating-joins-for-referenced-entities