private IEnumerable <string> ComputePrincipalKeyPropertiesNotFoundInPrincipalProperties()
        {
            List <string> strs = null;
            IEnumerator <IEdmStructuralProperty> enumerator = this.PrincipalEnd.EntityType.Key().GetEnumerator();

            using (enumerator)
            {
                Func <CsdlPropertyReference, bool> func = null;
                while (enumerator.MoveNext())
                {
                    IEdmStructuralProperty              current    = enumerator.Current;
                    CsdlReferentialConstraintRole       principal  = this.constraint.Principal;
                    IEnumerable <CsdlPropertyReference> properties = principal.Properties;
                    if (func == null)
                    {
                        func = (CsdlPropertyReference reference) => reference.PropertyName == current.Name;
                    }
                    CsdlPropertyReference csdlPropertyReference = properties.Where <CsdlPropertyReference>(func).FirstOrDefault <CsdlPropertyReference>();
                    if (csdlPropertyReference != null)
                    {
                        continue;
                    }
                    strs = CsdlSemanticsElement.AllocateAndAdd <string>(strs, current.Name);
                }
            }
            List <string>        strs1 = strs;
            IEnumerable <string> strs2 = strs1;

            if (strs1 == null)
            {
                strs2 = Enumerable.Empty <string>();
            }
            return(strs2);
        }
        private IEnumerable <EdmError> ComputeErrors()
        {
            List <EdmError> edmErrors  = null;
            IEdmEntityType  entityType = this.PrincipalEnd.EntityType;
            CsdlReferentialConstraintRole principal = this.constraint.Principal;
            CsdlReferentialConstraintRole dependent = this.constraint.Dependent;

            if (this.constraint.Principal.Role == this.constraint.Dependent.Role)
            {
                edmErrors = CsdlSemanticsElement.AllocateAndAdd <EdmError>(edmErrors, new EdmError(base.Location, EdmErrorCode.SameRoleReferredInReferentialConstraint, Strings.EdmModel_Validator_Semantic_SameRoleReferredInReferentialConstraint(this.constraint.Principal.Role)));
            }
            if (this.constraint.Dependent.Role != this.context.End1.Name && this.constraint.Dependent.Role != this.context.End2.Name)
            {
                edmErrors = CsdlSemanticsElement.AllocateAndAdd <EdmError>(edmErrors, new EdmError(base.Location, EdmErrorCode.InvalidRoleInRelationshipConstraint, Strings.CsdlParser_InvalidEndRoleInRelationshipConstraint(this.constraint.Dependent.Role, this.context.Name)));
            }
            if (this.constraint.Principal.Role != this.context.End1.Name && this.constraint.Principal.Role != this.context.End2.Name)
            {
                edmErrors = CsdlSemanticsElement.AllocateAndAdd <EdmError>(edmErrors, new EdmError(base.Location, EdmErrorCode.InvalidRoleInRelationshipConstraint, Strings.CsdlParser_InvalidEndRoleInRelationshipConstraint(this.constraint.Principal.Role, this.context.Name)));
            }
            if (edmErrors == null)
            {
                if (principal.Properties.Count <CsdlPropertyReference>() != dependent.Properties.Count <CsdlPropertyReference>())
                {
                    edmErrors = CsdlSemanticsElement.AllocateAndAdd <EdmError>(edmErrors, new EdmError(base.Location, EdmErrorCode.MismatchNumberOfPropertiesInRelationshipConstraint, Strings.EdmModel_Validator_Semantic_MismatchNumberOfPropertiesinRelationshipConstraint));
                }
                if (entityType.Key().Count <IEdmStructuralProperty>() != principal.Properties.Count <CsdlPropertyReference>() || this.PrincipalKeyPropertiesNotFoundInPrincipalProperties.Count <string>() != 0)
                {
                    string str = Strings.EdmModel_Validator_Semantic_InvalidPropertyInRelationshipConstraintPrimaryEnd(string.Concat(this.DependentEnd.DeclaringAssociation.Namespace, (char)46, this.DependentEnd.DeclaringAssociation.Name), this.constraint.Principal.Role);
                    edmErrors = CsdlSemanticsElement.AllocateAndAdd <EdmError>(edmErrors, new EdmError(base.Location, EdmErrorCode.BadPrincipalPropertiesInReferentialConstraint, str));
                }
                foreach (string dependentPropertiesNotFoundInDependentType in this.DependentPropertiesNotFoundInDependentType)
                {
                    string str1 = Strings.EdmModel_Validator_Semantic_InvalidPropertyInRelationshipConstraintDependentEnd(dependentPropertiesNotFoundInDependentType, this.constraint.Dependent.Role);
                    edmErrors = CsdlSemanticsElement.AllocateAndAdd <EdmError>(edmErrors, new EdmError(base.Location, EdmErrorCode.InvalidPropertyInRelationshipConstraint, str1));
                }
            }
            List <EdmError>        edmErrors1 = edmErrors;
            IEnumerable <EdmError> edmErrors2 = edmErrors1;

            if (edmErrors1 == null)
            {
                edmErrors2 = Enumerable.Empty <EdmError>();
            }
            return(edmErrors2);
        }
        private IEnumerable <string> ComputePrincipalKeyPropertiesNotFoundInPrincipalProperties()
        {
            List <string> properties = null;

            foreach (IEdmStructuralProperty principalKeyProperty in this.PrincipalEnd.EntityType.Key())
            {
                CsdlReferentialConstraintRole principalEnd = this.constraint.Principal;
                CsdlPropertyReference         correspondingPrimaryEndReference = (from reference in principalEnd.Properties
                                                                                  where reference.PropertyName == principalKeyProperty.Name
                                                                                  select reference).FirstOrDefault();
                if (correspondingPrimaryEndReference == null)
                {
                    properties = AllocateAndAdd(properties, principalKeyProperty.Name);
                }
            }

            return(properties ?? Enumerable.Empty <string>());
        }
        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);
        }
        private IEnumerable <EdmError> ComputeErrors()
        {
            List <EdmError> errors                     = null;
            IEdmEntityType  principalRoleType          = this.PrincipalEnd.EntityType;
            CsdlReferentialConstraintRole principalEnd = this.constraint.Principal;
            CsdlReferentialConstraintRole dependentEnd = this.constraint.Dependent;

            if (this.constraint.Principal.Role == this.constraint.Dependent.Role)
            {
                errors = AllocateAndAdd(errors, new EdmError(this.Location, EdmErrorCode.SameRoleReferredInReferentialConstraint, Edm.Strings.EdmModel_Validator_Semantic_SameRoleReferredInReferentialConstraint(this.constraint.Principal.Role)));
            }

            if (this.constraint.Dependent.Role != this.context.End1.Name && this.constraint.Dependent.Role != this.context.End2.Name)
            {
                errors = AllocateAndAdd(errors, new EdmError(this.Location, EdmErrorCode.InvalidRoleInRelationshipConstraint, Edm.Strings.CsdlParser_InvalidEndRoleInRelationshipConstraint(this.constraint.Dependent.Role, this.context.Name)));
            }

            if (this.constraint.Principal.Role != this.context.End1.Name && this.constraint.Principal.Role != this.context.End2.Name)
            {
                errors = AllocateAndAdd(errors, new EdmError(this.Location, EdmErrorCode.InvalidRoleInRelationshipConstraint, Edm.Strings.CsdlParser_InvalidEndRoleInRelationshipConstraint(this.constraint.Principal.Role, this.context.Name)));
            }

            // If there are already errors, property errors are likely to be meaningless.
            if (errors == null)
            {
                if (principalEnd.Properties.Count() != dependentEnd.Properties.Count())
                {
                    errors = AllocateAndAdd(
                        errors,
                        new EdmError(
                            this.Location,
                            EdmErrorCode.MismatchNumberOfPropertiesInRelationshipConstraint,
                            Edm.Strings.EdmModel_Validator_Semantic_MismatchNumberOfPropertiesinRelationshipConstraint));
                }

                if (principalRoleType.Key().Count() != principalEnd.Properties.Count() || this.PrincipalKeyPropertiesNotFoundInPrincipalProperties.Count() != 0)
                {
                    string errorMessage =
                        Edm.Strings.EdmModel_Validator_Semantic_InvalidPropertyInRelationshipConstraintPrimaryEnd(
                            this.DependentEnd.DeclaringAssociation.Namespace + '.' + this.DependentEnd.DeclaringAssociation.Name,
                            this.constraint.Principal.Role);
                    errors = AllocateAndAdd(
                        errors,
                        new EdmError(
                            this.Location,
                            EdmErrorCode.BadPrincipalPropertiesInReferentialConstraint,
                            errorMessage));
                }

                foreach (string propertyName in this.DependentPropertiesNotFoundInDependentType)
                {
                    string errorMessage = Edm.Strings.EdmModel_Validator_Semantic_InvalidPropertyInRelationshipConstraintDependentEnd(
                        propertyName,
                        this.constraint.Dependent.Role);

                    errors = AllocateAndAdd(
                        errors,
                        new EdmError(
                            this.Location,
                            EdmErrorCode.InvalidPropertyInRelationshipConstraint,
                            errorMessage));
                }
            }

            return(errors ?? Enumerable.Empty <EdmError>());
        }
 public CsdlReferentialConstraint(CsdlReferentialConstraintRole principal, CsdlReferentialConstraintRole dependent, CsdlDocumentation documentation, CsdlLocation location)
     : base(documentation, location)
 {
     this.principal = principal;
     this.dependent = dependent;
 }
 public CsdlReferentialConstraint(CsdlReferentialConstraintRole principal, CsdlReferentialConstraintRole dependent, CsdlDocumentation documentation, CsdlLocation location)
     : base(documentation, location)
 {
     this.principal = principal;
     this.dependent = dependent;
 }