Пример #1
0
 public DeferredForeignKeyMetadata(
     Type clrObjectType,
     CustomPropertyType entityProperty,
     CustomForeignKeyConstraintAttribute attribute,
     CustomForeignKeyConstraint consraint
     )
 {
     this.ClrObjectType  = clrObjectType;
     this.EntityProperty = entityProperty;
     this.Attribute      = attribute;
     this.Consraint      = consraint;
 }
Пример #2
0
        public void DefferedInitialization(
            CustomEntityType targetEntity,
            CustomPropertyType targetPrimaryKeyProperty
            )
        {
            Debug.Assert(!_readonly);

            _targetEntity             = targetEntity;
            _targetPrimaryKeyProperty = targetPrimaryKeyProperty;

            _readonly = true;
        }
Пример #3
0
        GetEntityProperties(
            Type clrObjectType,
            ICollection <EntityMemberCandidate> candidateList,
            ICollection <DeferredForeignKeyMetadata> deferredForeignKeys
            )
        {
            var primaryKeyNamesAttribute = TryGetAttribute <KeyAttribute>(
                clrObjectType);

            if (null == primaryKeyNamesAttribute || 0 == primaryKeyNamesAttribute.KeyNames.Count)
            {
                throw new CustomMetadataException(String.Format(
                                                      "EntityType mapping for CLR object type '{0}' is incomplete " +
                                                      "because it does not define any primary keys. Use {1} to " +
                                                      "specify at least one primary key.",
                                                      clrObjectType.Name,
                                                      typeof(KeyAttribute).Name
                                                      ));
            }
            ICollection <string> primaryKeyNames = new List <string>(primaryKeyNamesAttribute.KeyNames);

            Debug.Assert(primaryKeyNames.Count > 0);

            var collectedEntityProperties = new List <CustomPropertyType>();
            var candidateArray            = candidateList.ToArray();

            foreach (var propertyCandidate in candidateArray)
            {
                PropertyInfo clrProperty = propertyCandidate.ClrProperty;

                var propertyAttribute = TryGetAttribute <CustomPropertyAttribute>(clrProperty);
                if (null == propertyAttribute)
                {
                    continue;
                }

                var isComplexTypeProperty = TryGetAttribute <CustomComplexTypeAttribute>(
                    clrProperty.PropertyType) != null;

                var foreignKeyAttribute = TryGetAttribute <CustomForeignKeyConstraintAttribute>(
                    clrProperty);

                CustomForeignKeyConstraint foreignKeyConstraint = (null == foreignKeyAttribute ? null
                                                    : new CustomForeignKeyConstraint());

                bool isPrimaryKey = primaryKeyNames.Remove(clrProperty.Name);
                CustomPropertyType entityProperty = new CustomPropertyType(
                    propertyCandidate.NestedComplexTypePropertyPath,
                    clrProperty,
                    propertyAttribute.IsNullable,
                    propertyAttribute.IsReadOnly,
                    propertyAttribute.HasMaximumLength ?
                    propertyAttribute.MaximumLength : (int?)null,
                    propertyAttribute.IsStoreGenerated,
                    isPrimaryKey,
                    foreignKeyConstraint
                    );

                collectedEntityProperties.Add(entityProperty);
                candidateList.Remove(propertyCandidate);

                if (null != foreignKeyConstraint)
                {
                    deferredForeignKeys.Add(
                        new DeferredForeignKeyMetadata(
                            clrObjectType,
                            entityProperty,
                            foreignKeyAttribute,
                            foreignKeyConstraint
                            )
                        );
                }
            }

            if (primaryKeyNames.Count > 0)
            {
                throw new CustomMetadataException(String.Format(
                                                      "The following primary key properties [{0}] defined in " +
                                                      "{1} were not resolved to entity properties. Make sure " +
                                                      "that the listed properties are defined and annotated with {1}.",
                                                      CustomUtils.FormatCsvString(primaryKeyNames),
                                                      typeof(KeyAttribute).Name,
                                                      typeof(CustomPropertyAttribute).Name
                                                      ));
            }

            return(collectedEntityProperties);
        }