public Dictionary <int, string> getGamesIdFromDB() { using (var context = new GPCdbContext(_options, _configuration)) { var result = context.SteamGamesIdView.ToList(); return(result.ToDictionary(x => x.Id, y => y.Name)); } }
public void insertGamesIdToDB(Dictionary <int, string> dict) { var entityTbl = new List <LsteamGamesId>(); var ind = 0; var dictList = new List <Dictionary <int, string> > { new Dictionary <int, string>(), new Dictionary <int, string>() }; // first one - dictionary with key-pair values to add to DB; second one - dictionary with key-pair values to delete from DB dictList = DataManageClass.getDistinctGamesId(dict, getGamesIdFromDB()); using (var context = new GPCdbContext(_options, _configuration)) { try { if (dictList[0].Count > 0) { foreach (var rec in dictList[0]) { context.AddRange(new LsteamGamesId { Id = rec.Key, Name = rec.Value.Length < 255 ? rec.Value : rec.Value.Substring(0, 255) }); ind++; if ((ind % 1000 == 0) || (ind == dictList[0].Count)) { context.SaveChanges(); } } } } catch (Exception ex) { Console.WriteLine(ex); } } using (var context = new GPCdbContext(_options, _configuration)) { try { if (dictList[1].Count > 0) { foreach (var rec in dictList[1]) { context.RemoveRange(new LsteamGamesId { Id = rec.Key, Name = rec.Value.Length < 255 ? rec.Value : rec.Value.Substring(0, 255) }); ind++; if ((ind % 1000 == 0) || (ind == dictList[1].Count)) { context.SaveChanges(); } } } } catch (Exception ex) { Console.WriteLine(ex); } } }