Ejemplo n.º 1
0
        [ResourceConsumption(ResourceScope.Assembly | ResourceScope.Machine)]      // FindType method call.
        private MetaType InitDerivedTypes(TypeMapping typeMap)
        {
            Type type = ((MappedMetaModel)Model).FindType(typeMap.Name);

            if (type == null)
            {
                throw Error.CouldNotFindRuntimeTypeForMapping(typeMap.Name);
            }
            MappedType rowType = new MappedType(this.Model, this.Table, typeMap, type, this);

            return(this.InitInheritedType(typeMap, rowType));
        }
Ejemplo n.º 2
0
        [ResourceConsumption(ResourceScope.Assembly | ResourceScope.Machine)]      // InitDerivedTypes method call.
        private MetaType InitInheritedType(TypeMapping typeMap, MappedType type)
        {
            this.derivedTypes.Add(type.Type, type);

            if (typeMap.InheritanceCode != null)
            {             // Mapping with no inheritance code: For example, an unmapped intermediate class in a hierarchy.
                if (this.Discriminator == null)
                {
                    throw Error.NoDiscriminatorFound(type.Name);
                }

                if (type.Type.IsAbstract)
                {
                    throw Error.AbstractClassAssignInheritanceDiscriminator(type.Type);
                }

                object keyValue = DBConvert.ChangeType(typeMap.InheritanceCode, this.Discriminator.Type);
                foreach (object d in inheritanceCodes.Keys)
                {
                    // if the keys are equal, or if they are both strings containing only spaces
                    // they are considered equal
                    if ((keyValue.GetType() == typeof(string) && ((string)keyValue).Trim().Length == 0 &&
                         d.GetType() == typeof(string) && ((string)d).Trim().Length == 0) ||
                        object.Equals(d, keyValue))
                    {
                        throw Error.InheritanceCodeUsedForMultipleTypes(keyValue);
                    }
                }
                if (type.InheritanceCode != null)
                {
                    throw Error.InheritanceTypeHasMultipleDiscriminators(type);
                }
                type.SetInheritanceCode(keyValue);
                this.inheritanceCodes.Add(keyValue, type);
                if (typeMap.IsInheritanceDefault)
                {
                    if (this.inheritanceDefault != null)
                    {
                        throw Error.InheritanceTypeHasMultipleDefaults(type);
                    }
                    this.inheritanceDefault = type;
                }
            }

            // init sub-inherited types
            foreach (TypeMapping tm in typeMap.DerivedTypes)
            {
                this.InitDerivedTypes(tm);
            }

            return(type);
        }
Ejemplo n.º 3
0
        [ResourceConsumption(ResourceScope.Assembly | ResourceScope.Machine)] // InitDerivedTypes method call.
        private MetaType InitInheritedType(TypeMapping typeMap, MappedType type) {
            this.derivedTypes.Add(type.Type, type);

            if (typeMap.InheritanceCode != null) { // Mapping with no inheritance code: For example, an unmapped intermediate class in a hierarchy.
                if (this.Discriminator == null)
                    throw Error.NoDiscriminatorFound(type.Name);

                if (type.Type.IsAbstract)
                    throw Error.AbstractClassAssignInheritanceDiscriminator(type.Type);

                object keyValue = DBConvert.ChangeType(typeMap.InheritanceCode, this.Discriminator.Type);
                foreach (object d in inheritanceCodes.Keys) {
                    // if the keys are equal, or if they are both strings containing only spaces
                    // they are considered equal
                    if ((keyValue.GetType() == typeof(string) && ((string)keyValue).Trim().Length == 0 &&
                        d.GetType() == typeof(string) && ((string)d).Trim().Length == 0) ||
                        object.Equals(d, keyValue)) {
                        throw Error.InheritanceCodeUsedForMultipleTypes(keyValue);
                    }
                }
                if (type.inheritanceCode != null)
                    throw Error.InheritanceTypeHasMultipleDiscriminators(type);
                type.inheritanceCode = keyValue;
                this.inheritanceCodes.Add(keyValue, type);
                if (typeMap.IsInheritanceDefault) {
                    if (this.inheritanceDefault != null)
                        throw Error.InheritanceTypeHasMultipleDefaults(type);
                    this.inheritanceDefault = type;
                }
            }

            // init sub-inherited types
            foreach (TypeMapping tm in typeMap.DerivedTypes) {
                this.InitDerivedTypes(tm);
            }

            return type;
        }
Ejemplo n.º 4
0
 [ResourceConsumption(ResourceScope.Assembly | ResourceScope.Machine)] // FindType method call.
 private MetaType InitDerivedTypes(TypeMapping typeMap) {
     Type type = ((MappedMetaModel)Model).FindType(typeMap.Name);
     if (type == null)
         throw Error.CouldNotFindRuntimeTypeForMapping(typeMap.Name);
     MappedType rowType = new MappedType(this.Model, this.Table, typeMap, type, this);
     return this.InitInheritedType(typeMap, rowType);
 }