Hi there,

[Short version]
I have a mapping with two many-to-one relationship, the first with
@fetch="join" and the other with "fetch" select. Using the LINQ
provider (on Sql Server 2008), it seems that the generated SQL code is
the same. Is it possible?

[Extended version]
Here is my class hierarchy:

public class Widget
{
        public virtual Int32 Id { get; set; }
        public virtual string Tag { get; set; }
}
public class Bar
{
    public virtual Int32 Id { get; set; }
    public virtual string Label { get; set; }
    public virtual Widget Widget { get; set; }
}
public class Foo
{
    public virtual Int32 Id { get; set; }
    public virtual string Label { get; set; }
    public virtual Widget Widget { get; set; }
}

and here is the mapping:
<class name="Widget" table="Widget">...</class>
<class name="Foo" table="Foo">
    ....
    <many-to-one name="Widget" column="Widget" not-null="true"
fetch="select" lazy="false"/>
</class>
<class name="Bar" table="Bar">
    ....
    <many-to-one name="Widget" column="Widget" not-null="true"
fetch="join" lazy="false"/>
</class>

the folloqing code snippet:

var session = sessionFactory.OpenSession();
session.Query<Foo>().ToList();
session.Close();
session.Dispose();

session = sessionFactory.OpenSession();
session.Query<Bar>().ToList();
session.Close();
sessio.Dispose();

generates the following SQL code:

NHibernate: select foo0_.Id as Id1_, foo0_.Label as Label1_,
foo0_.Widget as Widget1_ from Foo foo0_
NHibernate: SELECT widget0_.Id as Id0_0_, widget0_.Tag as Tag0_0_ FROM
Widget widget0_ WHERE widget0_.Id=@p0;@p0 = 1 [Type: Int32 (0)]

NHibernate: select bar0_.Id as Id2_, bar0_.Label as Label2_,
bar0_.Widget as Widget2_ from Bar bar0_
NHibernate: SELECT widget0_.Id as Id0_0_, widget0_.Tag as Tag0_0_ FROM
Widget widget0_ WHERE widget0_.Id=@p0;@p0 = 1 [Type: Int32 (0)]

Now, even if I'm quite a newbie, these two SQL code fragments looks
like they are the same. But shouldn't the second one resolve the
Bar->Widget foreing key using a JOIN?

Thanks in advance,
Giulio

--

-- 
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.

Reply via email to