I have a problem in my app that I've reduced to a simple example. I
have an entity, Main, which has a reference to another entity, Part.
I'm trying to find a 'Main' that has a specific Part, e.g.:
Part part1 = session.Get<Part>(_part1Id);
Main main = session.Linq<Main>().FirstOrDefault(m => m.FirstPart
== part1);
However, the query ultimately getting executed is joining tmpMain to
tmpParts, even though tmpParts is not needed by the SQL criteria:
SELECT top 1 this_.MainID as MainID2_1_,
this_.FirstPartID as FirstPar2_2_1_,
firstpart1_.PartID as PartID3_0_,
firstpart1_.Name as Name3_0_
FROM dbo.tmpMains this_
left outer join dbo.tmpParts firstpart1_
on this_.FirstPartID = firstpart1_.PartID
WHERE this_.FirstPartID = 1 /* @p0 */
My classes are quite simple:
public class Main {
public virtual int Id { get; set; }
public virtual Part FirstPart { get; set; }
public class Part {
public virtual int Id { get; set; }
public virtual string Name { get; set; }
My mappings are:
<class name="IntTest.Main, IntTest" table="tmpMains">
<id name="Id" column="MainID" access="property" >
<generator class="identity" />
</id>
<many-to-one name="FirstPart" column="FirstPartID"
access="property" cascade="none" />
<class name="IntTest.Part, IntTest" table="tmpParts" mutable="true"
lazy="true">
<id name="Id" column="PartID" access="property" >
<generator class="identity" />
</id>
<property name="Name" column="Name" access="property" />
(Some of the extra attributes are probably redundant, but I've been
trying to migrate the extra attribute that my REAL app's FluentNH
mappings have, and I think FluentNH specifies things even if they're
defaulted).
My belief is that since Part is an entity, and entities are identified
by their "identity", and the identity of the Part in question is known
in tmpMains, that tmpParts shouldn't be involved. In other words...
SELECT top 1 this_.MainID as MainID2_1_,
this_.FirstPartID as FirstPar2_2_1_
FROM dbo.tmpMains this_
WHERE this_.FirstPartID = 1 /* @p0 */
Am I correct that I should expect that? If so, I'm at a loss for
what's causing it to NOT be this way. I don't have any fetch="join"
specified in the mapping, and I think I have everything set to be
lazy. There's something I'm not understanding.
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.