I have two csv files that I need to compare and merge together. There is a 'big' list with many records and columns of data and a 'small' list of the desired records and some additional data. The ultimate goal is to output the records on the small list joined with the data in the big list.
The below code seems to make the correct selects, but I am unsure if I should be looking at using JOIN
instead?
I like the cleanness of this solution in how it handles the CSV files in such few lines of code - let ... some.Split(',')
- and haven't come up with as clean of a way in using JOIN.
string[] small = System.IO.File.ReadAllLines(@"I:\\" + Environment.UserName + "\\smallfile.csv");
string[] big = System.IO.File.ReadAllLines(@"J:\\DROPFOLDERS\\bigfile.csv");
IEnumerable<MBSGroup> queryMBSObjects =
from smallLine in small
let splitSmallLine = smallLine.Split(',')
from bigLine in big
let splitBigLine = bigLine.Split(',')
where ((splitSmallLine[0] == splitBigLine[0] && splitSmallLine[2] == splitBigLine[1] && splitSmallLine[0] != "" && splitSmallLine[2] != "" && splitBigLine[1] != "") ||
(splitSmallLine[0] == splitBigLine[0] && splitSmallLine[2] == splitBigLine[5] && splitSmallLine[0] != "" && splitSmallLine[2] != "" && splitBigLine[5] != ""))
select new MBSGroup()
{
write data to merge object
};
List<MBSGroup> MBSlists = queryMBSObjects.ToList();