Ejemplo n.º 1
0
 internal UnmappedDataMember(MetaType declaringType, MemberInfo mi, int ordinal)
 {
     this.declaringType = declaringType;
     this.member        = mi;
     this.ordinal       = ordinal;
     this.type          = TypeSystem.GetMemberType(mi);
 }
        internal AttributedMetaDataMember(AttributedMetaType metaType, MemberInfo mi, int ordinal)
        {
            this.declaringType  = mi.DeclaringType;
            this.metaType       = metaType;
            this.member         = mi;
            this.ordinal        = ordinal;
            this.type           = TypeSystem.GetMemberType(mi);
            this.isNullableType = TypeSystem.IsNullableType(this.type);
            this.attrColumn     = (ColumnAttribute)Attribute.GetCustomAttribute(mi, typeof(ColumnAttribute));
            this.attrAssoc      = (AssociationAttribute)Attribute.GetCustomAttribute(mi, typeof(AssociationAttribute));
            this.attr           = (this.attrColumn != null) ? (DataAttribute)this.attrColumn : (DataAttribute)this.attrAssoc;
            if (this.attr != null && this.attr.Storage != null)
            {
                MemberInfo[] mis = mi.DeclaringType.GetMember(this.attr.Storage, BindingFlags.Instance | BindingFlags.NonPublic);
                if (mis == null || mis.Length != 1)
                {
                    throw Error.BadStorageProperty(this.attr.Storage, mi.DeclaringType, mi.Name);
                }
                this.storageMember = mis[0];
            }
            Type storageType = this.storageMember != null?TypeSystem.GetMemberType(this.storageMember) : this.type;

            this.isDeferred = IsDeferredType(storageType);
            if (attrColumn != null && attrColumn.IsDbGenerated && attrColumn.IsPrimaryKey)
            {
                // auto-gen identities must be synced on insert
                if ((attrColumn.AutoSync != AutoSync.Default) && (attrColumn.AutoSync != AutoSync.OnInsert))
                {
                    throw Error.IncorrectAutoSyncSpecification(mi.Name);
                }
            }
        }
Ejemplo n.º 3
0
        internal AttributedMetaDataMember(AttributedMetaType metaType, MemberInfo member, int ordinal)
        {
            declaringType        = member.DeclaringType;
            this.metaType        = metaType;
            this.member          = member;
            this.ordinal         = ordinal;
            type                 = TypeSystem.GetMemberType(member);
            isNullableType       = TypeSystem.IsNullableType(type);
            columnAttribute      = ((AttributedMetaModel)metaType.Model).TryGetColumnAttribute(member);
            associationAttribute = ((AttributedMetaModel)metaType.Model).TryGetAssociationAttribute(member);
            var attr = (columnAttribute == null) ? associationAttribute : (DataAttribute)columnAttribute;

            if (attr != null && attr.Storage != null)
            {
                var mis = member.DeclaringType.GetMember(attr.Storage, BindingFlags.Instance | BindingFlags.NonPublic);
                if (mis.Length != 1)
                {
                    throw Error.BadStorageProperty(attr.Storage, member.DeclaringType, member.Name);
                }
                storageMember = mis[0];
            }
            var storageType = storageMember == null ? type : TypeSystem.GetMemberType(storageMember);

            isDeferred = ((AttributedMetaModel)metaType.Model).IsDeferredMember(member, storageType, associationAttribute);

            // auto-gen identities must be synced on insert
            if ((columnAttribute != null) &&
                columnAttribute.IsDbGenerated &&
                columnAttribute.IsPrimaryKey &&
                (columnAttribute.AutoSync != AutoSync.Default) &&
                (columnAttribute.AutoSync != AutoSync.OnInsert))
            {
                throw Error.IncorrectAutoSyncSpecification(member.Name);
            }
        }
Ejemplo n.º 4
0
        internal MappedDataMember(MetaType declaringType, MemberInfo mi, MemberMapping map, int ordinal)
        {
            this.declaringType  = declaringType;
            this.member         = mi;
            this.ordinal        = ordinal;
            this.type           = TypeSystem.GetMemberType(mi);
            this.isNullableType = TypeSystem.IsNullableType(this.type);
            this.memberMap      = map;
            if (this.memberMap != null && this.memberMap.StorageMemberName != null)
            {
                MemberInfo[] mis = mi.DeclaringType.GetMember(this.memberMap.StorageMemberName, BindingFlags.Instance | BindingFlags.NonPublic);
                if (mis == null || mis.Length != 1)
                {
                    throw Error.BadStorageProperty(this.memberMap.StorageMemberName, mi.DeclaringType, mi.Name);
                }
                this.storageMember = mis[0];
            }
            Type storageType = this.storageMember != null?TypeSystem.GetMemberType(this.storageMember) : this.type;

            this.isDeferred = IsDeferredType(storageType);
            ColumnMapping cmap = map as ColumnMapping;

            if (cmap != null && cmap.IsDbGenerated && cmap.IsPrimaryKey)
            {
                // auto-gen identities must be synced on insert
                if ((cmap.AutoSync != AutoSync.Default) && (cmap.AutoSync != AutoSync.OnInsert))
                {
                    throw Error.IncorrectAutoSyncSpecification(mi.Name);
                }
            }
            if (cmap != null)
            {
                this.isPrimaryKey    = cmap.IsPrimaryKey;
                this.isVersion       = cmap.IsVersion;
                this.isDBGenerated   = cmap.IsDbGenerated || !string.IsNullOrEmpty(cmap.Expression) || this.isVersion;
                this.isDiscriminator = cmap.IsDiscriminator;
                this.canBeNull       = cmap.CanBeNull == null ? this.isNullableType || !this.type.IsValueType : (bool)cmap.CanBeNull;
                this.dbType          = cmap.DbType;
                this.expression      = cmap.Expression;
                this.updateCheck     = cmap.UpdateCheck;
                // auto-gen keys are always and only synced on insert
                if (this.IsDbGenerated && this.IsPrimaryKey)
                {
                    this.autoSync = AutoSync.OnInsert;
                }
                else if (cmap.AutoSync != AutoSync.Default)
                {
                    // if the user has explicitly set it, use their value
                    this.autoSync = cmap.AutoSync;
                }
                else if (this.IsDbGenerated)
                {
                    // database generated members default to always
                    this.autoSync = AutoSync.Always;
                }
            }
            this.mappedName = this.memberMap.DbName != null ? this.memberMap.DbName : this.member.Name;
        }
Ejemplo n.º 5
0
        private static Type GetIncludeTarget(MemberInfo mi)
        {
            Type memberType = TypeSystem.GetMemberType(mi);

            if (memberType.IsGenericType)
            {
                return(memberType.GetGenericArguments()[0]);
            }
            return(memberType);
        }
Ejemplo n.º 6
0
        private static void ValidateSubqueryMember(MemberInfo mi)
        {
            Type memberType = TypeSystem.GetMemberType(mi);

            if (memberType == null)
            {
                throw Error.SubqueryNotSupportedOn(mi);
            }
            if (!typeof(System.Collections.IEnumerable).IsAssignableFrom(memberType))
            {
                throw Error.SubqueryNotSupportedOnType(mi.Name, mi.DeclaringType);
            }
        }
Ejemplo n.º 7
0
        // Methods
        internal MappedDataMember(MetaType declaringType, MemberInfo mi, MemberMapping map, int ordinal)
        {
            this.declaringType  = declaringType;
            this.member         = mi;
            this.ordinal        = ordinal;
            this.type           = TypeSystem.GetMemberType(mi);
            this.isNullableType = TypeSystem.IsNullableType(this.type);
            this.memberMap      = map;
            if ((this.memberMap != null) && (this.memberMap.StorageMemberName != null))
            {
                MemberInfo[] member = mi.DeclaringType.GetMember(this.memberMap.StorageMemberName, BindingFlags.NonPublic | BindingFlags.Instance);
                if ((member == null) || (member.Length != 1))
                {
                    throw Error.BadStorageProperty(this.memberMap.StorageMemberName, mi.DeclaringType, mi.Name);
                }
                this.storageMember = member[0];
            }
            Type clrType = (this.storageMember != null) ? TypeSystem.GetMemberType(this.storageMember) : this.type;

            this.isDeferred = this.IsDeferredType(clrType);
            ColumnMapping mapping = map as ColumnMapping;

            if ((((mapping != null) && mapping.IsDbGenerated) && (mapping.IsPrimaryKey && (mapping.AutoSync != AutoSync.Default))) && (mapping.AutoSync != AutoSync.OnInsert))
            {
                throw Error.IncorrectAutoSyncSpecification(mi.Name);
            }
            if (mapping != null)
            {
                this.isPrimaryKey    = mapping.IsPrimaryKey;
                this.isVersion       = mapping.IsVersion;
                this.isDBGenerated   = (mapping.IsDbGenerated || !string.IsNullOrEmpty(mapping.Expression)) || this.isVersion;
                this.isDiscriminator = mapping.IsDiscriminator;
                this.canBeNull       = !mapping.CanBeNull.HasValue ? (this.isNullableType || !this.type.IsValueType) : mapping.CanBeNull.Value;
                this.dbType          = mapping.DbType;
                this.expression      = mapping.Expression;
                this.updateCheck     = mapping.UpdateCheck;
                if (this.IsDbGenerated && this.IsPrimaryKey)
                {
                    this.autoSync = AutoSync.OnInsert;
                }
                else if (mapping.AutoSync != AutoSync.Default)
                {
                    this.autoSync = mapping.AutoSync;
                }
                else if (this.IsDbGenerated)
                {
                    this.autoSync = AutoSync.Always;
                }
            }
            this.mappedName = (this.memberMap.DbName != null) ? this.memberMap.DbName : this.member.Name;
        }
Ejemplo n.º 8
0
        // Methods
        internal AttributedMetaDataMember(AttributedMetaType metaType, MemberInfo mi, int ordinal)
        {
            this.declaringType  = mi.DeclaringType;
            this.metaType       = metaType;
            this.member         = mi;
            this.ordinal        = ordinal;
            this.type           = TypeSystem.GetMemberType(mi);
            this.isNullableType = TypeSystem.IsNullableType(this.type);

            this.attributeProvider = this.MetaModel.AttributeProvider;

            /*
             * this.attrColumn = (ColumnAttribute)Attribute.GetCustomAttribute(mi, typeof(ColumnAttribute));
             * this.attrAssoc = (AssociationAttribute)Attribute.GetCustomAttribute(mi, typeof(AssociationAttribute));
             */
            this.attrColumn = attributeProvider.GetColumnAttribute(mi);
            this.attrAssoc  = attributeProvider.GetAssociationAttribute(mi);

            this.attr = (this.attrColumn != null) ? ((DataAttribute)attrColumn) : this.attrAssoc;
            if (attr != null && attr.Storage != null)
            {
                MemberInfo[] member = mi.DeclaringType.GetMember(this.attr.Storage, BindingFlags.NonPublic | BindingFlags.Instance);
                if (member == null || member.Length != 1)
                {
                    throw Mapping.Error.BadStorageProperty(this.attr.Storage, mi.DeclaringType, mi.Name);
                }
                this.storageMember = member[0];
            }
            Type entityType = (this.storageMember != null) ? TypeSystem.GetMemberType(this.storageMember) : this.type;

            this.isDeferred = this.IsDeferredType(entityType);
            if ((this.attrColumn != null && this.attrColumn.IsDbGenerated) &&
                (this.attrColumn.IsPrimaryKey && this.attrColumn.AutoSync != AutoSync.Default) &&
                (this.attrColumn.AutoSync != AutoSync.OnInsert))
            {
                throw Mapping.Error.IncorrectAutoSyncSpecification(mi.Name);
            }
        }