Reputation: 11247
I have the following table:
id
c_id
ch_id
I wanted to filter that list, to receive all the c_id
's that have all the IDs in a list for the ch_id
.
A c_id
can have several ch_id
's. If for example, the list contains '2,5
' integers. I should get the c_id's which each one has at least the values found in that list.
For example, I get in returns c_id
3, because the following rows correspond to the query:
c_id
also has ch_id = 6
, but it doesn't matter, because it at least need to have those ch_id's that are in the list. I have no idea how to approach this, any help will be appreciated.
I though about grouping the table by c_id
, but the table might be very big and I think it might make the query very slow after some time.
I'm trying to achieve this query in LINQ/Entity Framework.
Upvotes: 0
Views: 99
Reputation: 26917
Worrying about grouping being too slow sounds like premature optimization to me. Grouping is the right solution, and possibly faster methods would depend on knowing a lot more details about your data.
var ans = from r in src group r by r.c_id into rg where desiredch.All(ach => rg.Any(r => r.ch_id == ach)) select rg.Key;
Upvotes: 1