I have a DataTable containing two columns, both of which is a list of ID’s, with a many-many relationship:
ResourceID AttributeID ---------- ----------- 1 1 1 2 1 3 2 1 2 3 3 3
etc…
Given a list of AttributeID’s, I want to obtain a list of ResourceID’s that have ALL the supplied AttributeID’s.
I initially thought to do this:
string[] attributes = "....";
dv.RowFilter = "AttributeID in (" + String.Join(",", attributes) + ")";
return dv.ToTable(true, "ResourceID").AsEnumerable().Select(x => (int)x[0]).ToList();
but that gives me a list that have ANY of the supplied AttributeID’s.
My list of attributes is currently a string array, but that can be changed if necessary. My result set is currently returned as a List of ResourceID’s, but that’s negotiable too.
Thanks in advance!
For anybody who is looking to do the same thing, here’s the solution that I found – essentially grouping my result set and counting the number of items in each group to check that it matches the number of items in my list of supplied attributes.