> I'm using NHibernate 3 Alpha, trying to use the Fetch() extension method
> over IQueryable<>:
>       var categorias = this.context.Query<Categoria>();
>       var queryCategorias = from c in categorias
>                                   from i in c.Itens
>                                   from iu in i.ItensUsuario
>                                   where c.Tipo == tipoCategoria &&
> (i.Default || iu.Usuario.Id == idUsuario)
>                                   select c;
>      var listCategorias = queryCategorias.Fetch(c => c.Itens).ToList();
> 
> 
> The SQL produced correctly "fetches" the child elements for each parent.
> However, two joins are produced for the same table: a INNER JOIN (itens1)
> and a LEFT OUTER JOIN (itens3):

        Likely a bug in the linq provider. Cause is this:
var queryCategorias = from c in categorias      // A
                      from i in c.Itens         // B
                      from iu in i.ItensUsuario // C

A and B form a 'cross' join (SelectMany call). However 'from i in c.Itens'
forms a left join (if FK in Itens is nullable) which represents the _same_
thing. The linq provider should test for this and replace the cross join
with the left join, however instead if a) makes the mistake of inserting it
as an inner join (error #1) and b) adds the left join after it. 

it's a cross join because:
var q = from c in session.Query<Customer>()
        from o in session.Query<Order>()
        where // predicate
         select c;

the 'predicate' clause can't be used as an ON clause, but has to be
specified as a WHERE clause, leaving the join as a cross join. I think the
linq provider simply does: select c from customer x, order o where ...;

        Workaround is to formulate the joins hardcoded: (don't know the
entity names, field names, you've to correct thos) 
 var queryCategorias = from c in categorias
                       join i in session.Query<Itens> on c.Id equals
i.Categoria.Id
                       join iu in session.Query<ItensUsiario> on i.Id equals
ui.Iten.Id                                                        where
c.Tipo == tipoCategoria && (i.Default || iu.Usuario.Id == idUsuario
                       select c;

                FB

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