public void Import(string filePath) { Vocabulary v = findOrCreate(); StreamReader sr = new StreamReader(filePath); string line; Console.WriteLine("Creating database objects..."); while ((line = sr.ReadLine()) != null) { var row = line.Split('$'); int pos = languageFrom.Item2; string spelling = row[pos].Trim(); if (spelling == "") { continue; } var translations = new List<Tuple<string, string>>(); foreach (var lng in languagesTo) { pos = lng.Item2; if ( pos >= row.Length ) { translations.Clear(); break; } translations.Add(Tuple.Create(lng.Item1, row[pos])); } if (translations.Count == 0) { Console.WriteLine("Warning: {0} - word ignored, no translations found", spelling); continue; } Word item = new Word { Spelling = spelling, Added = DateTime.Now, State = State.New}; database.Words.InsertOnSubmit(item); v.Words.Add(item); foreach (var t in translations) { if (t.Item2.Trim().Length == 0) continue; Translation tr = new Translation { Spelling = t.Item2, Language = t.Item1 }; item.Translations.Add(tr); database.Translations.InsertOnSubmit(tr); } } Console.WriteLine("Submiting changes..."); database.SubmitChanges(); }
private void detach_translation(Translation entity) { NotifyPropertyChanging("Translation"); entity.Word = null; NotifyPropertyChanged("Translation"); }
private void attach_translation(Translation entity) { NotifyPropertyChanging("Translation"); entity.Word = this; NotifyPropertyChanged("Translation"); }