public static void AddOrUpdateEntity(DBWords db, Word entity) { var dbEntity = db.Words.Where(w => w.Name == entity.Name).FirstOrDefault(); if (dbEntity != null) { dbEntity.Frequency += entity.Frequency; } else { db.Add(entity); } db.SaveChanges(); }
public static void AddOrUpdateEntity(DBWords db, List <Word> entities) { foreach (var entity in entities) { var dbEntity = db.Words.Where(w => w.Name == entity.Name).FirstOrDefault(); if (dbEntity == null) { dbEntity = db.Words.Local.Where(w => w.Name == entity.Name).FirstOrDefault(); } if (dbEntity != null) { dbEntity.Frequency += entity.Frequency; } else { db.Add(entity); } } db.SaveChanges(); }