This will be a bit abstract but I have a method like this:
private int[] ReturnLogicalGroupingAForOrderedElements(List<int> elements) {
//sql query or linq query
//returns an int[] in case there are more than one matching set.
}
Let’s say the List passed contains the following elements: 3,6 and 9. I need to find the exact same list, elements in the same order, sharing the same logical grouping (whatever it is), from a datatable source.
I have a datatable with the following columns (all of them int values):
LogicalGroupingA, LogicalGroupingB, Element, ElementOrder
I need to find and identify that all of the above elements (3,6,9) exists across several rows, sharing the same logical grouping. Example:
7,1,3,1
7,1,6,2
7,1,9,3
If all of these are found then I want to return the value from LogicalGroupingA which is 7.
But consider this, there might be a different set of rows (sharing same logicalgrouping) that are:
4,1,3,1
4,1,6,2
4,1,9,3
4,1,5,4
The query should only return the desired value if the complete series of elements is exactly what is asked for (here the first three elements are equal to the list queried for but since there’s a fourth element here it is not equal). Assume that the datatable rows are mixed. LogicalGroupingA can contain many of LogicalGroupingB which again can contain many Elements.
Originally I had a very simple datatable setup where a colum contained a string like “3,6,9” that I would have to parse in my logic. The aim by creating this new numeric datatable was to make it as fast as possible (in theory). I’m open for an alternative datatable structure if it can improve on this but mainly I’m asking for help forming the desired query (sql or linq) for the above table.
EDIT: Maybe a bit bad timing posting the question as I will be gone from my dev machine for the next two days but rest assure I will give the proper points & votes (and comments) once I am back and have tested the suggestions. Thanks for your patience.
1 Answer