To Take A Dynamically Built Search Expression As An Extension Method?

dynamic-linq extension-methods linq

Question

I think we are basically looking for a extension method that could take in an IQueryable and return an IQueryable based on an entire query statement and not just the where statement.

Example of what we would like for a Search Method:

IRepository<Person> repository = new Repository<Person>();
var results = repository.GetQuery().Include("Names").Search([dynamic linq here]);

We currently have where we build a dynamic linq statement inside the where method

IRepository<Person> repository = new Repository<Person>();
var results = repository.GetQuery().Include("Names").Where([dynamic linq here]);

The problem with that approach is that we want to do include SelectMany and Select on the actual dynamic linq query. You cannot use the SelectMany inside a Where method unless you are actually going into sub properties of sub properties. We would like to do something like the following dynamic linq statement.

SelectMany("Names").Where("LastName.Contains(@0)", "Smith").Select("Person")
1
1
3/17/2011 3:25:29 PM

Popular Answer

We solved this issue without having to use a extension method. We were able to use a similar query that works inside a Where method.

So instead of...

SelectMany("Names").Where("LastName.Contains(@0)", "Smith").Select("Person") 

We were able to get the same result with the following query that can be inside a Where method.

Where.("Names.Select(LastName).Contains(@0)", "Smith)

Then when just had to add a Contains Aggregate to the Dynamic Linq library.

http://blog.walteralmeida.com/2010/05/advanced-linq-dynamic-linq-library-add-support-for-contains-extension-.html

The SelectMany had sent us off on a wild goose chase!

1
3/18/2011 4:20:42 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow