I think the formatting messed your code up - you commented out the *(ddt.IsClose() == false) &&,* right?
NH.Linq doesn't support arbitrary method calls like you had in your first query. It would have to be able to run your query against the DB, and then filter the result set in memory with your method call - it is not smart enough to do all of that. The workaround is to do what you did - run the query against the DB (by calling ToList) and then filtering that in memory with your method call. On Wed, Mar 18, 2009 at 8:57 AM, Alessandro C. < [email protected]> wrote: > > I found this workaround: > > .Where( > ddt => // don't work with Linq2NHibernate > (ddt.IsClose() == false) && > (ddt.NotReadyToUse == false) && > (customer == null || ddt.Ddt.Customer == customer) > && > (article == null || ddt.Article == article)) > .OrderBy(ddt => ddt.Ddt.Dateddt) > .ToList() > .Where(ddt => ddt.IsClose() == false ); > > Is that the right way? > > Thanks, > > On 18 Mar, 11:35, "Alessandro C." <[email protected]> > wrote: > > I'm using Linq to NHibernate and I have problem using a query like the > > following (fragment): > > > > .Where( > > ddt => (ddt.IsClose() == false) && > > (ddt.NotReadyToUse == false) && > > (customer == null || ddt.Ddt.Customer == customer) && > > (article == null || ddt.Article == article)) > > .OrderBy(ddt => ddt.Ddt.Dateddt).ToList(); > > > > The problem is "ddt.IsClose() == false" because it generates the > > following Sql statement (fragment): > > > > .....WHERE (((not ((this_.NotReadyToUse = @p0)) and not (1=1)) > > and ......etc. etc. > > > > As you can see it generates "and not (1=1)" that is always false and > > therefore the query doesn't return any rows. More the function IsClose > > () id never executed. > > > > My question is: Can I use methods inside the Where, if yes, what is > > wrong in my Where clause. > > > > Thanks, > > Alessandro Cavalieri > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "NHibernate Contrib - Development Group" 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.ar/group/nhcdevs?hl=en -~----------~----~----~----~------~----~------~--~---
