private static void writeToBeachedLanguageTable(CSVRow row, HashSet<ADDITIONAL_LANGUAGE> hashSetAttidionalLanguage) { foreach (var item in hashSetAttidionalLanguage) { using (var context = new LPPEntities()) { context.Database.Log = Console.Write; var beached = context.BEACHEDs.FirstOrDefault(s => s.BEACHED_ID.Equals(row.BeachedClass.BEACHED_ID)); var language = context.ADDITIONAL_LANGUAGE.FirstOrDefault(s => s.LANG_NAME.Equals(item.LANG_NAME)); beached.BEACHED_LANGUAGE.Add(new BEACHED_LANGUAGE { FLUENCY = 2, BEACHED = beached, ADDITIONAL_LANGUAGE = language }); context.SaveChanges(); } } }
private CSVRow RowToCSVRowObject(string[] fields) { CSVRow currentCSVRow = new CSVRow(); currentCSVRow.AdditionalLanuageClass = RowToAdditionalLanguageObject(fields); currentCSVRow.BeachedClass = RowToBeachedObject(fields); currentCSVRow.BeachedLanguageClass = RowToBeachedLanguageObject(currentCSVRow.AdditionalLanuageClass, currentCSVRow.BeachedClass); return currentCSVRow; }
public static bool writeRowToDatabase(CSVRow Row) { try { writeToAdditionalLanguageTable(Row.AdditionalLanuageClass); writeToBeachedTable(Row.BeachedClass); writeToBeachedLanguageTable(Row, Row.AdditionalLanuageClass); } catch (Exception e) { Console.WriteLine(e.StackTrace); return false; } return true; }