private void Save() { foreach (var o in Added) { GetTable(o.GetType()).Add(o); } foreach (var o in Removed) { var table = GetTable(o.GetType()); if (!table.Contains(o)) { throw new InvalidOperationException("Removed untracked entity"); } table.Remove(o); } Added.Clear(); Updated.Clear(); Removed.Clear(); }
public void ApplyTo(Dbf dbf) { foreach (var record in Inserted) { dbf.Records.Add(record); } foreach (int index in Deleted) { dbf.DeleteRecord(index); } foreach (var kvp in Updated) { dbf.Records[kvp.Key] = kvp.Value; if (dbf.Fields.Any(f => f.Type == DbfFieldType.Memo)) { foreach (var field in dbf.Fields) { if (field.Type != DbfFieldType.Memo) { continue; } var memoEntry = kvp.Value[field.Name] as DbfMemoEntry; if (!dbf.Memo.ContainsEntry(memoEntry)) { // this is a new memo kvp.Value[field.Name] = dbf.CreateMemoEntry(memoEntry.Value); } } } } Inserted.Clear(); Updated.Clear(); Deleted.Clear(); }