Impossible to load one-to-one association with LINQ for composite-id

Description

When you use one-to-one mapping for object, that have with LINQ provider it's impossible to load property that contains associated object if it is not explicitly loaded in select clause.

Example:
<class name="ExternalField">
<composite-id>
<key-property name="Id" />
<key-property name="Id2" />
</composite-id>
</class>

<class name="Field">
<composite-id>
<key-property name="Id" />
<key-property name="Id2" />
</composite-id>
<one-to-one name="ExternalField" lazy="false" fetch="join" />
</class>
var fields = session.Query<Field>()
.ToList()
.Where(it => it.ExternalField != null).ToList();

There will be no object in final list, even if DB have such. Same queries work when using NHibernate.Linq.

Environment

None

Attachments

1

Activity

Show:

Alex Zaytsev 
March 27, 2019 at 10:35 PM

Moved here.

Alex Zaytsev 
May 29, 2013 at 11:25 PM

The problem in HQL

Ricardo Peres 
May 29, 2013 at 9:49 AM

If you take out the first ToList() on your LINQ query, the problem appears:

var fields = session.Query<Field>().Where(it => it.ExternalField != null).ToList();

select
field0_.Id as Id1_,
field0_.Id2 as Id2_1_
from
Field field0_
where
(
field0_.Id, field0_.Id2
) is not null

NHibernate is building a wrong SQL.

Fixed

Details

Assignee

Reporter

Labels

Components

Fix versions

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created May 29, 2013 at 5:28 AM
Updated March 27, 2019 at 10:35 PM
Resolved March 27, 2019 at 10:35 PM
Who's Looking?