/// <summary> /// Returns whether two instances have equivalent keys /// </summary> /// <param name="instance1">The first instance to compare</param> /// <param name="instance2">The second instance to compare</param> /// <returns>True if the keys are equal, otherwise false</returns> private bool AreKeysEqual(ResourceInstance instance1, ResourceInstance instance2) { ExceptionUtilities.CheckArgumentNotNull(instance1, "instance1"); ExceptionUtilities.CheckArgumentNotNull(instance2, "instance2"); ExceptionUtilities.Assert(instance1.IsEntityType, "Key equality check only supported on entities"); ExceptionUtilities.Assert(instance2.IsEntityType, "Key equality check only supported on entities"); if (instance1.ResourceSetName != instance2.ResourceSetName) { return false; } var type1 = this.metadataHelper.ResourceTypes.Single(t => t.FullName == instance1.ResourceTypeName); var type2 = this.metadataHelper.ResourceTypes.Single(t => t.FullName == instance2.ResourceTypeName); if (!type1.KeyProperties.SequenceEqual(type2.KeyProperties)) { return false; } foreach (var keyProperty in type1.KeyProperties) { var value1 = instance1.Where(pair => pair.Key == keyProperty.Name).Select(pair => pair.Value).SingleOrDefault(); var value2 = instance2.Where(pair => pair.Key == keyProperty.Name).Select(pair => pair.Value).SingleOrDefault(); if (!ResourceInstance.ArePropertyValuesEqual(value1, value2)) { return false; } } return true; }