I know I don't need nested query here, I've mentioned that I have a
workaround.
This is more theoretical question - shouldn't this query work, or at
least throw an exception instead of producing wrong SQL query?

Regards,
Adam

On 25 Paź, 22:18, [email protected] wrote:
> I don't think you need a nested query here.
>
> Can't you do something like
>
> from c in session.Query<Continent>
> where c.Name == 'your value here'
> from cc in c.Countries
> select cc.Rivers
>
> -Fran
>
> On , Adam Bar <[email protected]> wrote:
>
>
>
>
>
>
>
> > I have simple model with two-step relationship: River has many
> > Countries, Country has one Continent. I want to query for all rivers
> > located within given continent. For code simplicity, I've tried to use
> > two separate LINQ queries:
> > var countries = session.Query()
> > .Where(c => c.Continent.Id == continentId);
> > var data = session.Query()
> > .Where(r => (r.Countries.Where(c => countries.Contains(c))).Any())
> > .ToList();
> > The Where condition in second query is satisfied if at least one of
> > river's countries exists in the country list for given continent. I
> > don't call ToList() on first query, so I assume it is not run
> > separately but merged (nested) into second one (or at least
> > NotSupportedException is thrown or something). Here is the SQL query
> > that actually runs:
> > select river0_.Id as Id2_,
> > river0_.Name as Name2_
> > from "River" river0_
> > where exists (select country2_.Id
> > from CountryToRiver countries1_,
> > "Country" country2_
> > where river0_.Id = countries1_.River_id
> > and countries1_.Country_id = country2_.Id
> > and (exists (select country3_.Id
> > from "Country" country3_
> > where country3_.Id =
> > country2_.Id)))
> > What do we have here? It gets all rivers, filter it for rivers that
> > are within countries (country2_ alias), that are equal to ANY country
> > (country3_ alias) - no continent condition at all! The query is
> > merged, it runs without errors and silently produces unexpected, wrong
> > results.
> > I know that this is not the best way of querying (I've described the
> > workaround I use in a blog post:  
> >http://notherdev.blogspot.com/2011/10/linq-pitfalls-nested-queries.html),
> > but I feel it should work and I'll glad to know is this a bug or
> > expected behaviour and I'm doing something wrong.
> > Thanks!
> > --
> > 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.

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