Exemplo n.º 1
0
        internal override void Configure(
            AssociationType associationType,
            AssociationEndMember dependentEnd,
            EntityTypeConfiguration entityTypeConfiguration)
        {
            // ISSUE: object of a compiler-generated type is created
            // ISSUE: variable of a compiler-generated type
            ForeignKeyConstraintConfiguration.\u003C\u003Ec__DisplayClasse cDisplayClasse1 = new ForeignKeyConstraintConfiguration.\u003C\u003Ec__DisplayClasse();
            // ISSUE: reference to a compiler-generated field
            cDisplayClasse1.entityTypeConfiguration = entityTypeConfiguration;
            if (!this._dependentProperties.Any <PropertyInfo>())
            {
                return;
            }
            IEnumerable <PropertyInfo> propertyInfos = this._dependentProperties.AsEnumerable <PropertyInfo>();

            if (!this.IsFullySpecified)
            {
                // ISSUE: reference to a compiler-generated field
                if (EntityTypeExtensions.GetClrType(dependentEnd.GetEntityType()) != cDisplayClasse1.entityTypeConfiguration.ClrType)
                {
                    return;
                }
                // ISSUE: reference to a compiler-generated method
                IEnumerable <\u003C\u003Ef__AnonymousType41 <PropertyInfo, int?> > source = this._dependentProperties.Select(new Func <PropertyInfo, \u003C\u003Ef__AnonymousType41 <PropertyInfo, int?> >(cDisplayClasse1.\u003CConfigure\u003Eb__0));
                if (this._dependentProperties.Count > 1 && source.Any(p => !p.ColumnOrder.HasValue))
                {
                    ReadOnlyMetadataCollection <EdmProperty> dependentKeys = dependentEnd.GetEntityType().KeyProperties;
                    if (dependentKeys.Count != this._dependentProperties.Count || !source.All(fk =>
                    {
                        // ISSUE: variable of a compiler-generated type
                        ForeignKeyConstraintConfiguration.\u003C\u003Ec__DisplayClasse cDisplayClasse = cDisplayClasse1;
                        var fk1 = fk;
                        return(dependentKeys.Any <EdmProperty>((Func <EdmProperty, bool>)(p => p.GetClrPropertyInfo().IsSameAs(fk1.PropertyInfo))));
                    }))
                    {
                        // ISSUE: reference to a compiler-generated field
                        throw Error.ForeignKeyAttributeConvention_OrderRequired((object)cDisplayClasse1.entityTypeConfiguration.ClrType);
                    }
                    propertyInfos = dependentKeys.Select <EdmProperty, PropertyInfo>((Func <EdmProperty, PropertyInfo>)(p => p.GetClrPropertyInfo()));
                }
                else
                {
                    propertyInfos = source.OrderBy(p => p.ColumnOrder).Select(p => p.PropertyInfo);
                }
            }
            List <EdmProperty> edmPropertyList = new List <EdmProperty>();

            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                EdmProperty primitiveProperty = dependentEnd.GetEntityType().GetDeclaredPrimitiveProperty(propertyInfo);
                if (primitiveProperty == null)
                {
                    throw Error.ForeignKeyPropertyNotFound((object)propertyInfo.Name, (object)dependentEnd.GetEntityType().Name);
                }
                edmPropertyList.Add(primitiveProperty);
            }
            AssociationEndMember  otherEnd = associationType.GetOtherEnd(dependentEnd);
            ReferentialConstraint referentialConstraint = new ReferentialConstraint((RelationshipEndMember)otherEnd, (RelationshipEndMember)dependentEnd, (IEnumerable <EdmProperty>)otherEnd.GetEntityType().KeyProperties, (IEnumerable <EdmProperty>)edmPropertyList);

            if (otherEnd.IsRequired())
            {
                referentialConstraint.ToProperties.Each <EdmProperty, bool>((Func <EdmProperty, bool>)(p => p.Nullable = false));
            }
            associationType.Constraint = referentialConstraint;
        }