tags:

views:

328

answers:

0

I have a series of linq queries.

and I am stuck on combining these queries.

Let's assume I have two simple queries.

private static readonly Func(DataContext, string, IQueryable(Users)) CompiledQuery1 = CompiledQuery.Compile((DataContext context, string name) => from user in context.Table() where user.name == name select user)

private static readonly Func(DataContext, string, IQueryable(Users)) CompiledQuery2 = CompiledQuery.Compile((DataContext context, string state) => from user in context.Table() where user.state== state select user)

In the method, I want to find a user with name "John" and state "NY" so I made the second query like this:

private static readonly Func(DataContext, string, IQueryable(Users), IQueryable(Users)) CompiledQuery2 = CompiledQuery.Compile((DataContext context, string state, IQueryable(Users) users) => from user in users where user.state== state select user)

In the method

...

var nameFilteredUsers = CompiledQuery1(_dataContext, "John");

var stateFilteredUsers = CompiledQuery2(_dataContext, "NY", nameFilteredUsers);

...

But I got exception saying CompiledQuery does not allow using Enumerable (or List) as a parameter.

Is there a way to combine multiple compiled queries and build expression tree?

(I know I can do something like (where name == "John" && state == "NY") but the original query should be divided to two or more.)

I appreciate answers in advance.

Thanks