public override bool Equals(object obj) { if (this == obj) { return(true); } if (obj == null) { return(false); } if (this.GetType() != obj.GetType()) { return(false); } DbEntityOperation other = (DbEntityOperation)obj; if (entity == null) { if (other.entity != null) { return(false); } } else if (!entity.Equals(other.entity)) { return(false); } if (operationType != other.operationType) { return(false); } return(true); }
/// <summary> /// Assumptions: /// a) all operations in the set work on entities such that the entities implement <seealso cref="HasDbReferences"/>. /// b) all operations in the set work on the same type (ie. all operations are INSERTs or DELETEs). /// /// </summary> protected internal virtual IList <DbEntityOperation> sortByReferences(SortedSet <DbEntityOperation> preSorted) { // copy the pre-sorted set and apply final sorting to list IList <DbEntityOperation> opList = new List <DbEntityOperation>(preSorted); for (int i = 0; i < opList.Count; i++) { DbEntityOperation currentOperation = opList[i]; DbEntity currentEntity = currentOperation.Entity; ISet <string> currentReferences = currentOperation.FlushRelevantEntityReferences; // check whether this operation must be placed after another operation int moveTo = i; for (int k = i + 1; k < opList.Count; k++) { DbEntityOperation otherOperation = opList[k]; DbEntity otherEntity = otherOperation.Entity; ISet <string> otherReferences = otherOperation.FlushRelevantEntityReferences; if (currentOperation.OperationType == INSERT) { // if we reference the other entity, we need to be inserted after that entity if (currentReferences != null && currentReferences.Contains(otherEntity.Id)) { moveTo = k; break; // we can only reference a single entity } } else { // UPDATE or DELETE // if the other entity has a reference to us, we must be placed after the other entity if (otherReferences != null && otherReferences.Contains(currentEntity.Id)) { moveTo = k; // cannot break, there may be another entity further to the right which also references us } } } if (moveTo > i) { opList.Remove(i); opList.Insert(moveTo, currentOperation); i--; } } return(opList); }
public virtual bool addOperation(DbEntityOperation newOperation) { if (newOperation.OperationType == INSERT) { return(getInsertsForType(newOperation.EntityType, true).Add(newOperation)); } else if (newOperation.OperationType == DELETE) { return(getDeletesByType(newOperation.EntityType, true).Add(newOperation)); } else { // UPDATE return(getUpdatesByType(newOperation.EntityType, true).Add(newOperation)); } }