Пример #1
0
 public bool TryGetEntityType(Type clrType, out CustomEntityType entityType)
 {
     CustomUtils.CheckArgumentNotNull(clrType, "clrType");
     if (_clrObjectTypeMap.TryGetValue(clrType, out entityType))
     {
         return(true);
     }
     return(false);
 }
Пример #2
0
        public CustomEntitySetType(
            CustomEntityType baseElementType,
            string name
            )
        {
            CustomUtils.CheckArgumentNotNull(baseElementType, "baseElementType");
            CustomUtils.CheckArgumentNotNull(name, "name");

            _baseElementType = baseElementType;
            _name            = name;
        }
Пример #3
0
        public void DefferedInitialization(
            CustomEntityType targetEntity,
            CustomPropertyType targetPrimaryKeyProperty
            )
        {
            Debug.Assert(!_readonly);

            _targetEntity             = targetEntity;
            _targetPrimaryKeyProperty = targetPrimaryKeyProperty;

            _readonly = true;
        }
Пример #4
0
        public void Add(CustomEntityType entityType)
        {
            CustomEntityType otherEntityType;

            if (_clrObjectTypeMap.TryGetValue(entityType.ClrObjectType, out otherEntityType))
            {
                throw new CustomMetadataException(String.Format(
                                                      "CLR object type '{0}' is already mapped to entity type '{0}'.",
                                                      entityType.ClrObjectType,
                                                      otherEntityType
                                                      ));
            }
            _clrObjectTypeMap[entityType.ClrObjectType] = entityType;
        }
Пример #5
0
        private void CollectEntitySets(
            Type clrObjectType,
            CustomEntityType entityType,
            ICollection <CustomEntitySetType> collectedEntitySets
            )
        {
            var entitySetAttribute = TryGetAttribute <CustomTargetEntitySetAttribute>(clrObjectType, false);

            if (null != entitySetAttribute)
            {
                foreach (string name in entitySetAttribute.EntitySetNames)
                {
                    collectedEntitySets.Add(new CustomEntitySetType(entityType, name));
                }
            }
        }
Пример #6
0
        public void DefferedInitialization(
            bool isPrimaryEnd,
            CustomEntitySetType entitySetType,
            CustomEntityType entityType,
            CustomNavigationPropertyType relatedProperty,
            CustomMultiplicity multiplicity
            )
        {
            Debug.Assert(!_readonly);

            _isPrimaryEnd    = isPrimaryEnd;
            _entitySetType   = entitySetType;
            _entityType      = entityType;
            _relatedProperty = relatedProperty;
            _multiplicity    = multiplicity;

            _readonly = true;
        }
Пример #7
0
        private CustomEntitySetType InferEntitySetFromEntityType(
            CustomMetadataWorkspace metadata,
            CustomEntityType entityType,
            string context
            )
        {
            var candidateEntitySets = metadata.EntitySets.Where(es => es.BaseElementType
                                                                .IsAssignableFrom(entityType))
                                      .Select(es => es);

            if (candidateEntitySets.Count() == 1)
            {
                return(candidateEntitySets.First());
            }
            throw new CustomMetadataException(String.Format(
                                                  "Cannot infer type of entity set from given entity type '{0}' " +
                                                  "in the context of '{1}' because there are either no or several " +
                                                  "entity sets with suitable base element type: [{2}]. Specify " +
                                                  "which entity set to use.",
                                                  entityType,
                                                  context,
                                                  CustomUtils.FormatCsvString(candidateEntitySets.Select(e => e.Name))
                                                  ));
        }
Пример #8
0
        private CustomMetadataWorkspace Build()
        {
            CustomMetadataWorkspace workspace = new CustomMetadataWorkspace();

            ICollection <DeferredForeignKeyMetadata> deferredForeignKeys
                = new List <DeferredForeignKeyMetadata>();

            ICollection <DeferredRelationshipMetadata> deferredRelationships
                = new List <DeferredRelationshipMetadata>();

            ICollection <CustomEntitySetType> collectedEntitySets = new List <CustomEntitySetType>();

            foreach (Type clrObjectType in _clrObjectTypeCollection)
            {
                ICollection <EntityMemberCandidate> memberCandidates = CollectFlatMemberCandidateList(clrObjectType);

                ICollection <CustomPropertyType> properties = GetEntityProperties(
                    clrObjectType,
                    memberCandidates,
                    deferredForeignKeys
                    );

                ICollection <CustomNavigationPropertyType> navigationProperties
                    = GetEntityNavigationProperties(
                          clrObjectType,
                          memberCandidates,
                          deferredRelationships
                          );

                CustomEntityType entityType = new CustomEntityType(
                    clrObjectType,
                    properties,
                    navigationProperties
                    );

                CollectEntitySets(clrObjectType, entityType, collectedEntitySets);

                workspace.Add(entityType);

                if (memberCandidates.Count > 0)
                {
                    /*
                     * warn user about unmapped properties?
                     * Debug.Fail(String.Format(
                     *              "Found unmapped properties [{0}] in CLR object '{1}'.",
                     *              CustomUtils.FormatCsvString(memberCandidates.Select(m => m.ToString())), clrObjectType.Name
                     *      ));
                     */
                }
            }

            foreach (CustomEntitySetType entitySet in collectedEntitySets)
            {
                workspace.Add(entitySet);
            }

            FixUpDeferredForeignKeyMetadata(workspace, deferredForeignKeys);
            FixUpDeferredRelationshipMetadata(workspace, deferredRelationships);

            workspace.ValidateAndLock();
            return(workspace);
        }
Пример #9
0
        public override bool Equals(object obj)
        {
            CustomEntityType other = obj as CustomEntityType;

            return(null == other ? false : _clrObjectType.Equals(other._clrObjectType));
        }
Пример #10
0
 public bool IsAssignableFrom(CustomEntityType otherEntityType)
 {
     return(_clrObjectType.IsAssignableFrom(otherEntityType._clrObjectType));
 }