Take Expression<Func<T,bool>>, taking Func<T,bool> doesn't leave any chance to parse it.
Tuna Toksöz Eternal sunshine of the open source mind. http://devlicio.us/blogs/tuna_toksoz http://tunatoksoz.com http://twitter.com/tehlike On Fri, Feb 5, 2010 at 1:05 PM, Ili <[email protected]> wrote: > My guess is that it is me who is doing this wrong and apologies > upfront for being stupid. > > I am getting very strange behaviour when I run the following test - > > [Test] > public void Test_LoadCustomerALFKIAndAllOrdersUsingRepository() > { > > > HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize(); > > using (ISession session = NHibernateHelper.OpenSession()) > { > var customers1 = session.Linq<Customer>().Where(x => > x.CustomerId == "ALFKI"); > > foreach (Customer c in customers1) > { > Customer cc = c; > } > } > var customerRepository = new NHRepository<Customer>(); > var customers = customerRepository.GetByCriteria(x => > x.CustomerId == "ALFKI"); > foreach (Customer c in customers) > { > Customer cc = c; > } > > } > > The first Nhibernate linq query directly uses the session object and > the sql that is generated is spot on - i.e. > > SELECT .... > FROM dbo.Customers this_ > WHERE this_.CustomerId = 'ALFKI' /* @p0 */ > > Now, the 2nd query calls a generic method called - GetByCriteria nd > passes in the closure as a parameter, this however generates the sql > query - > > SELECT .... > FROM dbo.Customers this_ > > I would have expected this to run the filtered query as with the 1st > case with the filter but it retrieves the entire table from the > database and then does the filtering. > > my GetByCriteria function looks like this - > > public IEnumerable<T> GetByCriteria(Func<T, bool> exp) > { > dac.OpenSession(); > return dac.Session.Linq<T>().Where(exp); > } > > Thanks, > Ilias > > -- > 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]<nhusers%[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.
