public void ExportData(string path = "C:\\Users\\Andrii\\Documents\\Visual Studio 2013\\Projects\\WebSite1\\Domain.Models\\Частотний словник іменників.txt") { StreamReader file = new StreamReader(path); string readedLine; string []splitedString; byte indexWordInSplitString = 1; Word word=new Word(); using(IsterikaGameDBEntities _db=new IsterikaGameDBEntities()) { int count = 0; int limitOfWords = 1000; while ((readedLine=file.ReadLine())!=null) { count++; // to control if all work right but not to all db if (count > limitOfWords) { splitedString = readedLine.Split('{', ','); word.Word1 = splitedString[indexWordInSplitString]; _db.Words.Add(word); _db.SaveChanges(); } } file.Close(); } }
public void GetAllWordsFromDB(List<Player>[] commands) { List<int> idOfWords = new List<int>(); CreatePlayers.WriteNumberOfWords(); using (var _db = new IsterikaGameDBEntities()) { int countOfWordInDb = _db.Words.Count(); for (byte i = 0; i < commands.Length; i++) { for (byte j = 0; j < commands[i].Count(); j++) { for (byte y = 0; y < CreatePlayers.NumberOfWordsByPlayer; y++) { idOfWords.Add(random.Next(0, countOfWordInDb)); } } } var words = from w in _db.Words where idOfWords.Contains(w.id) select w; wordsFromDB = words.ToList(); } }