Skip to content

Instantly share code, notes, and snippets.

@jinan-kordab
Created May 28, 2018 00:53
Show Gist options
  • Save jinan-kordab/cbdf9b3268b23901472eeff2ca85a849 to your computer and use it in GitHub Desktop.
Save jinan-kordab/cbdf9b3268b23901472eeff2ca85a849 to your computer and use it in GitHub Desktop.
Second business rule for semi identical records
var line = data[i].ToString().Split('\t');
var nextLine = data[i + 1].ToString().Split('\t');
if (line[0].ToString().Trim() == nextLine[0].ToString().Trim())
{
//The fourth column in our data text file that we already read - text file
String PKcriteria = nextLine[3].ToString().Trim();
//ALL LRT3FK values, or , our Foreign Key Values Table
// We, in a way import all of it to our business layer, then use it
var allforeignkeyvaluesin_LRT3FK = (from fkey in LRT3FK
where fkey.COLFOUR == 4816
select fkey).ToList();
// Pick the one key that we need, since the two tables are related with constraints
var FKtoInsert = allforeignkeyvaluesin_LRT3FK.Where(x => x.COLTHREE.ToString().Trim() == PKcriteria.ToString().Trim()).Select(x => x.PKID).SingleOrDefault();
DateTime nw = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
// Add row to data table
table.Rows.Add(new object[] { 4816, nextLine[0].ToString().Trim(), nw, Convert.ToByte(nextLine[4].ToString().Trim()), nextLine[1].ToString().Trim(), FKtoInsert });
i = i + 1;
}
else
{
//The fourth column in our data text file that we already read - text file
String PKcriteria = line[3].ToString().Trim();
//ALL LRT3FK values, or , our Foreign Key Values Table
// We, in a way import all of it to our business layer, then use it
var allforeignkeyvaluesin_LRT3FK = (from fkey in LRT3FK
where fkey.COLFOUR == 4816
select fkey).ToList();
// Pick the one key that we need, since the two tables are related with constraints
var FKtoInsert = allforeignkeyvaluesin_LRT3FK.Where(x => x.COLTHREE.ToString().Trim() == PKcriteria.ToString().Trim()).Select(x => x.PKID).SingleOrDefault();
DateTime nw = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
// Add row to data table
table.Rows.Add(new object[] { 4816, line[0].ToString().Trim(), nw, Convert.ToByte(line[4].ToString().Trim()), line[1].ToString().Trim(), FKtoInsert });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment