ninjanye / SearchExtensions

Library of IQueryable extension methods to perform searching
MIT License
331 stars 52 forks source link

EF Include() not working when used after search extensions #8

Closed maximtarasov closed 8 years ago

maximtarasov commented 8 years ago

Hello.

If lazy loading disabled and you are using Include to load nav props after using of search extensions - Include simply dont work.

Example code: query.Search(a => a.Street.Name) .Containing(keywords).Include(a=>a.Street)

ninjanye commented 8 years ago

Thanks for logging this issue @maximtarasov. I'll try and look into this today or tomorrow and let you know my findings

ninjanye commented 8 years ago

Hi @maximtarasov

I suddenly realised that I have come across this issue once before. The solution/workaround is to reorder your code so that the expression tree builds the Includes() before the search. For example

query.Include(a => a.Street)
     .Search(a => a.Street.Name)
     .Containing(keywords);

Hope this help you get around the issue. I will look into a potential solution so others do not experience the same thing or creating a blog post explaining the workaround

Thanks again for getting in touch