There is an operation to import records into the database, about 7000 lines are loaded at a time. Lines can be updated, in this case it is necessary to replace the old ones. However, I get a DuplicateKey error (the key is a composite of 3 fields).
using (var db = new Context()) { using (var dbTransaction = db.Database.BeginTransaction()) { try { MasterAccount MA = db.MasterAccounts.FirstOrDefault(i => i.AccountId == AccountID); if (MA == null) return false; if (MA.History == null) MA.History = MH; else MA.History.AddRange(MH); db.SaveChanges(); dbTransaction.Commit(); return true; } catch { dbTransaction.Rollback(); return false; } } } //MA.History = List<History> //MH тоже самое Actually the question is how to solve such problems without checking each element for existence in the database and not manually updating it? *
mergeadds, if not, updates, if there is - Senior PomidorMergeis what, where to look? - SYLGetSession().Merge(T t)- Senior PomidorGetSession().Merge(T t)is still not clear where it came from. Can a complete example? - SYL