Created
January 15, 2020 19:00
-
-
Save JakeKalkman/670d61253d99921836848bbf3198c5c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void CombineResults(string groupCol, string targetCol, string differingCol) | |
{ | |
var groupedResults = new Dictionary<string, IList<Dictionary<string, string>>>(); | |
foreach(var dbRow in QueryResults) | |
{ | |
if (!groupedResults.ContainsKey(dbRow[groupCol])) | |
{ | |
groupedResults.Add(dbRow[groupCol], new List<Dictionary<string, string>>()); | |
} | |
groupedResults[dbRow[groupCol]].Add(dbRow); | |
} | |
var combinedResults = new List<Dictionary<string, string>>(); | |
foreach(var resultKey in groupedResults.Keys) | |
{ | |
var results = groupedResults[resultKey]; | |
var combinedResult = new Dictionary<string, string>(); | |
foreach(var dbResult in results) | |
{ | |
foreach(var key in dbResult.Keys) | |
{ | |
if (!combinedResult.ContainsKey(key)) | |
{ | |
combinedResult.Add(key, dbResult[key]); | |
} | |
if(key == differingCol) | |
{ | |
combinedResult.Add(dbResult[differingCol], dbResult[targetCol]); | |
} | |
} | |
} | |
combinedResults.Add(combinedResult); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment