private IEnumerable <IEdmStructuralProperty> ComputeDependentProperties()
        {
            List <IEdmStructuralProperty> edmStructuralProperties = new List <IEdmStructuralProperty>();
            IEdmEntityType entityType               = this.DependentEnd.EntityType;
            var            principalRoleType        = this.PrincipalEnd.EntityType;
            CsdlReferentialConstraintRole principal = this.constraint.Principal;
            CsdlReferentialConstraintRole dependent = this.constraint.Dependent;

            if (principalRoleType.Key().Count <IEdmStructuralProperty>() != principal.Properties.Count <CsdlPropertyReference>() || principal.Properties.Count <CsdlPropertyReference>() != dependent.Properties.Count <CsdlPropertyReference>() || this.PrincipalKeyPropertiesNotFoundInPrincipalProperties.Count <string>() != 0 || this.DependentPropertiesNotFoundInDependentType.Count <string>() != 0)
            {
                edmStructuralProperties = new List <IEdmStructuralProperty>();
                foreach (CsdlPropertyReference property in dependent.Properties)
                {
                    EdmError[] edmError = new EdmError[1];
                    edmError[0] = new EdmError(base.Location, EdmErrorCode.TypeMismatchRelationshipConstraint, Strings.CsdlSemantics_ReferentialConstraintMismatch);
                    edmStructuralProperties.Add(new BadProperty(entityType, property.PropertyName, edmError));
                }
            }
            else
            {
                IEnumerator <IEdmStructuralProperty> enumerator = this.PrincipalEnd.EntityType.Key().GetEnumerator();
                using (enumerator)
                {
                    Func <CsdlPropertyReference, bool> func = null;
                    while (enumerator.MoveNext())
                    {
                        IEdmStructuralProperty current = enumerator.Current;
                        IEnumerable <CsdlPropertyReference> properties = principal.Properties;
                        if (func == null)
                        {
                            func = (CsdlPropertyReference reference) => principalRoleType.FindProperty(reference.PropertyName).Equals(current);
                        }
                        CsdlPropertyReference csdlPropertyReference = properties.Where <CsdlPropertyReference>(func).FirstOrDefault <CsdlPropertyReference>();
                        int num = principal.IndexOf(csdlPropertyReference);
                        CsdlPropertyReference  csdlPropertyReference1 = dependent.Properties.ElementAt <CsdlPropertyReference>(num);
                        IEdmStructuralProperty edmStructuralProperty  = entityType.FindProperty(csdlPropertyReference1.PropertyName) as IEdmStructuralProperty;
                        edmStructuralProperties.Add(edmStructuralProperty);
                    }
                }
            }
            return(edmStructuralProperties);
        }
        private IEnumerable <IEdmStructuralProperty> ComputeDependentProperties()
        {
            // Sort the ReferentialConstraint principal/dependent property pairs into the order of the principal end.
            // If any part of the constraint is bad, return all dependent properties as bad.
            List <IEdmStructuralProperty> properties   = new List <IEdmStructuralProperty>();
            IEdmEntityType dependentRoleType           = this.DependentEnd.EntityType;
            IEdmEntityType principalRoleType           = this.PrincipalEnd.EntityType;
            CsdlReferentialConstraintRole principalEnd = this.constraint.Principal;
            CsdlReferentialConstraintRole dependentEnd = this.constraint.Dependent;

            if ((principalRoleType.Key().Count() == principalEnd.Properties.Count() && principalEnd.Properties.Count() == dependentEnd.Properties.Count()) &&
                this.PrincipalKeyPropertiesNotFoundInPrincipalProperties.Count() == 0 &&
                this.DependentPropertiesNotFoundInDependentType.Count() == 0)
            {
                foreach (IEdmStructuralProperty principalKeyProperty in this.PrincipalEnd.EntityType.Key())
                {
                    CsdlPropertyReference correspondingPrimaryEndReference = (from reference in principalEnd.Properties
                                                                              where principalRoleType.FindProperty(reference.PropertyName).Equals(principalKeyProperty)
                                                                              select reference).FirstOrDefault();
                    int correspondingPrimaryEndIndex             = principalEnd.IndexOf(correspondingPrimaryEndReference);
                    CsdlPropertyReference  dependentEndReference = dependentEnd.Properties.ElementAt(correspondingPrimaryEndIndex);
                    IEdmStructuralProperty dependentProperty     = dependentRoleType.FindProperty(dependentEndReference.PropertyName) as IEdmStructuralProperty;
                    properties.Add(dependentProperty);
                }
            }
            else
            {
                properties = new List <IEdmStructuralProperty>();
                foreach (CsdlPropertyReference prop in dependentEnd.Properties)
                {
                    properties.Add(new BadProperty(dependentRoleType, prop.PropertyName, new EdmError[] { new EdmError(this.Location, EdmErrorCode.TypeMismatchRelationshipConstraint, Edm.Strings.CsdlSemantics_ReferentialConstraintMismatch) }));
                }
            }

            return(properties);
        }