1

I'm trying to get all items that have a data equal to (1 OR 2) AND a data equal to (6 OR 7)

var oneFromEachList = new[] {
    new[] {1,2}, // 1 OR 2
    new[] {6,7}, // AND 6 OR 7
};

// item.dataList is an IEnumerable<int>
DbSet<Table>.Where(item => oneFromEachList.All(list => item.dataList.Any(list.Contains)))

This query is what I want to do, but it can't be converted to SQL, I get: "The nested query is not supported. Operation1='Case' Operation2='Collect'"

Note that the oneFromEachList object is known before the query is executed (it's not from the database). I guess it's possible to build an Expression by composing .Where statements? This seems very complicated for what it is though...

1
  • I'm not clear what you're trying to do, but Dynamic LINQ makes it easy to construct complex Where clauses. dynamiclinq.codeplex.com Commented Oct 23, 2015 at 16:32

1 Answer 1

1

I think this is what you're going for:

var query = DbSet<Table>()
foreach(var list in oneFromEachList)
   query = query.Where(item => item.dataList.Any(list.Contains));

You could turn this into a one-liner by using Aggregate():

oneFromEachList.Aggregate(DbSet<Table>(), (q, l) => q.Where(item => item.dataList.Any(l.Contains)));

But either way you're not going to be able to accomplish what you're looking for without either composing multiple Where clauses or doing some manual expression building.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.