コード例 #1
0
ファイル: ColumnAttribute.cs プロジェクト: zxd60/linq2db
        /// <summary>
        /// Copy constructor.
        /// </summary>
        /// <param name="ca">Attribute to clone.</param>
        internal ColumnAttribute(ColumnAttribute ca)
        {
            MemberName        = ca.MemberName;
            Configuration     = ca.Configuration;
            Name              = ca.Name;
            DataType          = ca.DataType;
            DbType            = ca.DbType;
            Storage           = ca.Storage;
            IsDiscriminator   = ca.IsDiscriminator;
            SkipOnEntityFetch = ca.SkipOnEntityFetch;
            PrimaryKeyOrder   = ca.PrimaryKeyOrder;
            IsColumn          = ca.IsColumn;
            CreateFormat      = ca.CreateFormat;

            if (ca.HasSkipOnInsert())
            {
                SkipOnInsert = ca.SkipOnInsert;
            }
            if (ca.HasSkipOnUpdate())
            {
                SkipOnUpdate = ca.SkipOnUpdate;
            }
            if (ca.HasCanBeNull())
            {
                CanBeNull = ca.CanBeNull;
            }
            if (ca.HasIsIdentity())
            {
                IsIdentity = ca.IsIdentity;
            }
            if (ca.HasIsPrimaryKey())
            {
                IsPrimaryKey = ca.IsPrimaryKey;
            }
            if (ca.HasLength())
            {
                Length = ca.Length;
            }
            if (ca.HasPrecision())
            {
                Precision = ca.Precision;
            }
            if (ca.HasScale())
            {
                Scale = ca.Scale;
            }
            if (ca.HasOrder())
            {
                Order = ca.Order;
            }
        }
コード例 #2
0
ファイル: ColumnAttribute.cs プロジェクト: jack128/linq2db
        internal ColumnAttribute(ColumnAttribute ca)
        {
            MemberName      = ca.MemberName;
            Configuration   = ca.Configuration;
            Name            = ca.Name;
            DataType        = ca.DataType;
            DbType          = ca.DbType;
            Storage         = ca.Storage;
            IsDiscriminator = ca.IsDiscriminator;
            PrimaryKeyOrder = ca.PrimaryKeyOrder;
            IsColumn        = ca.IsColumn;

            if (ca.HasSkipOnInsert()) SkipOnInsert = ca.SkipOnInsert;
            if (ca.HasSkipOnUpdate()) SkipOnUpdate = ca.SkipOnUpdate;
            if (ca.HasCanBeNull())    CanBeNull    = ca.CanBeNull;
            if (ca.HasIsIdentity())   IsIdentity   = ca.IsIdentity;
            if (ca.HasIsPrimaryKey()) IsPrimaryKey = ca.IsPrimaryKey;
            if (ca.HasLength())       Length       = ca.Length;
            if (ca.HasPrecision())    Precision    = ca.Precision;
            if (ca.HasScale())        Scale        = ca.Scale;
        }
コード例 #3
0
        /// <summary>
        /// Creates descriptor instance.
        /// </summary>
        /// <param name="mappingSchema">Mapping schema, associated with descriptor.</param>
        /// <param name="columnAttribute">Column attribute, from which descriptor data should be extracted.</param>
        /// <param name="memberAccessor">Column mapping member accessor.</param>
        public ColumnDescriptor(MappingSchema mappingSchema, ColumnAttribute columnAttribute, MemberAccessor memberAccessor)
        {
            MemberAccessor = memberAccessor;
            MemberInfo     = memberAccessor.MemberInfo;

            if (MemberInfo.IsFieldEx())
            {
                var fieldInfo = (FieldInfo)MemberInfo;
                MemberType = fieldInfo.FieldType;
            }
            else if (MemberInfo.IsPropertyEx())
            {
                var propertyInfo = (PropertyInfo)MemberInfo;
                MemberType = propertyInfo.PropertyType;
            }

            MemberName      = columnAttribute.MemberName ?? MemberInfo.Name;
            ColumnName      = columnAttribute.Name ?? MemberInfo.Name;
            Storage         = columnAttribute.Storage;
            PrimaryKeyOrder = columnAttribute.PrimaryKeyOrder;
            IsDiscriminator = columnAttribute.IsDiscriminator;
            DataType        = columnAttribute.DataType;
            DbType          = columnAttribute.DbType;
            CreateFormat    = columnAttribute.CreateFormat;

            if (columnAttribute.HasLength())
            {
                Length = columnAttribute.Length;
            }
            if (columnAttribute.HasPrecision())
            {
                Precision = columnAttribute.Precision;
            }
            if (columnAttribute.HasScale())
            {
                Scale = columnAttribute.Scale;
            }

            if (Storage == null)
            {
                StorageType = MemberType;
                StorageInfo = MemberInfo;
            }
            else
            {
                var expr = Expression.PropertyOrField(Expression.Constant(null, MemberInfo.DeclaringType), Storage);
                StorageType = expr.Type;
                StorageInfo = expr.Member;
            }

            var defaultCanBeNull = false;

            if (columnAttribute.HasCanBeNull())
            {
                CanBeNull = columnAttribute.CanBeNull;
            }
            else
            {
                var na = mappingSchema.GetAttribute <NullableAttribute>(MemberAccessor.TypeAccessor.Type, MemberInfo, attr => attr.Configuration);

                if (na != null)
                {
                    CanBeNull = na.CanBeNull;
                }
                else
                {
                    CanBeNull        = mappingSchema.GetCanBeNull(MemberType);
                    defaultCanBeNull = true;
                }
            }

            if (columnAttribute.HasIsIdentity())
            {
                IsIdentity = columnAttribute.IsIdentity;
            }
            else if (MemberName.IndexOf(".") < 0)
            {
                var a = mappingSchema.GetAttribute <IdentityAttribute>(MemberAccessor.TypeAccessor.Type, MemberInfo, attr => attr.Configuration);
                if (a != null)
                {
                    IsIdentity = true;
                }
            }

            SequenceName = mappingSchema.GetAttribute <SequenceNameAttribute>(memberAccessor.TypeAccessor.Type, MemberInfo, attr => attr.Configuration);

            if (SequenceName != null)
            {
                IsIdentity = true;
            }

            SkipOnInsert = columnAttribute.HasSkipOnInsert() ? columnAttribute.SkipOnInsert : IsIdentity;
            SkipOnUpdate = columnAttribute.HasSkipOnUpdate() ? columnAttribute.SkipOnUpdate : IsIdentity;

            if (defaultCanBeNull && IsIdentity)
            {
                CanBeNull = false;
            }

            if (columnAttribute.HasIsPrimaryKey())
            {
                IsPrimaryKey = columnAttribute.IsPrimaryKey;
            }
            else if (MemberName.IndexOf(".") < 0)
            {
                var a = mappingSchema.GetAttribute <PrimaryKeyAttribute>(MemberAccessor.TypeAccessor.Type, MemberInfo, attr => attr.Configuration);

                if (a != null)
                {
                    IsPrimaryKey    = true;
                    PrimaryKeyOrder = a.Order;
                }
            }

            if (DbType == null || DataType == DataType.Undefined)
            {
                var a = mappingSchema.GetAttribute <DataTypeAttribute>(MemberAccessor.TypeAccessor.Type, MemberInfo, attr => attr.Configuration);

                if (a != null)
                {
                    if (DbType == null)
                    {
                        DbType = a.DbType;
                    }

                    if (DataType == DataType.Undefined && a.DataType.HasValue)
                    {
                        DataType = a.DataType.Value;
                    }
                }
            }
        }
コード例 #4
0
ファイル: ColumnDescriptor.cs プロジェクト: rabbers/linq2db
        public ColumnDescriptor(MappingSchema mappingSchema, ColumnAttribute columnAttribute, MemberAccessor memberAccessor)
        {
            MappingSchema  = mappingSchema;
            MemberAccessor = memberAccessor;
            MemberInfo     = memberAccessor.MemberInfo;

            if (MemberInfo.IsFieldEx())
            {
                var fieldInfo = (FieldInfo)MemberInfo;
                MemberType = fieldInfo.FieldType;
            }
            else if (MemberInfo.IsPropertyEx())
            {
                var propertyInfo = (PropertyInfo)MemberInfo;
                MemberType = propertyInfo.PropertyType;
            }

            MemberName      = columnAttribute.MemberName ?? MemberInfo.Name;
            ColumnName      = columnAttribute.Name ?? MemberInfo.Name;
            Storage         = columnAttribute.Storage;
            PrimaryKeyOrder = columnAttribute.PrimaryKeyOrder;
            IsDiscriminator = columnAttribute.IsDiscriminator;
            DataType        = columnAttribute.DataType;
            DbType          = columnAttribute.DbType;

            if (columnAttribute.HasLength())
            {
                Length = columnAttribute.Length;
            }
            if (columnAttribute.HasPrecision())
            {
                Precision = columnAttribute.Precision;
            }
            if (columnAttribute.HasScale())
            {
                Scale = columnAttribute.Scale;
            }

            var defaultCanBeNull = false;

            if (columnAttribute.HasCanBeNull())
            {
                CanBeNull = columnAttribute.CanBeNull;
            }
            else
            {
                var na = mappingSchema.GetAttribute <NullableAttribute>(MemberInfo, attr => attr.Configuration);

                if (na != null)
                {
                    CanBeNull = na.CanBeNull;
                }
                else
                {
                    CanBeNull        = mappingSchema.GetCanBeNull(MemberType);
                    defaultCanBeNull = true;
                }
            }

            if (columnAttribute.HasIsIdentity())
            {
                IsIdentity = columnAttribute.IsIdentity;
            }
            else
            {
                var a = mappingSchema.GetAttribute <IdentityAttribute>(MemberInfo, attr => attr.Configuration);
                if (a != null)
                {
                    IsIdentity = true;
                }
            }

            SkipOnInsert = columnAttribute.HasSkipOnInsert() ? columnAttribute.SkipOnInsert : IsIdentity;
            SkipOnUpdate = columnAttribute.HasSkipOnUpdate() ? columnAttribute.SkipOnUpdate : IsIdentity;

            if (defaultCanBeNull && IsIdentity)
            {
                CanBeNull = false;
            }

            if (columnAttribute.HasIsPrimaryKey())
            {
                IsPrimaryKey = columnAttribute.IsPrimaryKey;
            }
            else
            {
                var a = mappingSchema.GetAttribute <PrimaryKeyAttribute>(MemberInfo, attr => attr.Configuration);

                if (a != null)
                {
                    IsPrimaryKey    = true;
                    PrimaryKeyOrder = a.Order;
                }
            }
        }
コード例 #5
0
ファイル: ColumnDescriptor.cs プロジェクト: ronnyek/linq2db
		public ColumnDescriptor(MappingSchema mappingSchema, ColumnAttribute columnAttribute, MemberAccessor memberAccessor)
		{
			MappingSchema  = mappingSchema;
			MemberAccessor = memberAccessor;
			MemberInfo     = memberAccessor.MemberInfo;

			if (MemberInfo.IsFieldEx())
			{
				var fieldInfo = (FieldInfo)MemberInfo;
				MemberType = fieldInfo.FieldType;
			}
			else if (MemberInfo.IsPropertyEx())
			{
				var propertyInfo = (PropertyInfo)MemberInfo;
				MemberType = propertyInfo.PropertyType;
			}

			MemberName      = columnAttribute.MemberName ?? MemberInfo.Name;
			ColumnName      = columnAttribute.Name       ?? MemberInfo.Name;
			Storage         = columnAttribute.Storage;
			PrimaryKeyOrder = columnAttribute.PrimaryKeyOrder;
			IsDiscriminator = columnAttribute.IsDiscriminator;
			DataType        = columnAttribute.DataType;
			DbType          = columnAttribute.DbType;
			CreateFormat    = columnAttribute.CreateFormat;

			if (columnAttribute.HasLength   ()) Length    = columnAttribute.Length;
			if (columnAttribute.HasPrecision()) Precision = columnAttribute.Precision;
			if (columnAttribute.HasScale    ()) Scale     = columnAttribute.Scale;

			if (Storage == null)
			{
				StorageType = MemberType;
				StorageInfo = MemberInfo;
			}
			else
			{
				var expr = Expression.PropertyOrField(Expression.Constant(null, MemberInfo.DeclaringType), Storage);
				StorageType = expr.Type;
				StorageInfo = expr.Member;
			}

			var defaultCanBeNull = false;

			if (columnAttribute.HasCanBeNull())
				CanBeNull = columnAttribute.CanBeNull;
			else
			{
				var na = mappingSchema.GetAttribute<NullableAttribute>(MemberInfo, attr => attr.Configuration);

				if (na != null)
				{
					CanBeNull = na.CanBeNull;
				}
				else
				{
					CanBeNull        = mappingSchema.GetCanBeNull(MemberType);
					defaultCanBeNull = true;
				}
			}

			if (columnAttribute.HasIsIdentity())
				IsIdentity = columnAttribute.IsIdentity;
			else
			{
				var a = mappingSchema.GetAttribute<IdentityAttribute>(MemberInfo, attr => attr.Configuration);
				if (a != null)
					IsIdentity = true;
			}

			SkipOnInsert = columnAttribute.HasSkipOnInsert() ? columnAttribute.SkipOnInsert : IsIdentity;
			SkipOnUpdate = columnAttribute.HasSkipOnUpdate() ? columnAttribute.SkipOnUpdate : IsIdentity;

			if (defaultCanBeNull && IsIdentity)
				CanBeNull = false;

			if (columnAttribute.HasIsPrimaryKey())
				IsPrimaryKey = columnAttribute.IsPrimaryKey;
			else
			{
				var a = mappingSchema.GetAttribute<PrimaryKeyAttribute>(MemberInfo, attr => attr.Configuration);

				if (a != null)
				{
					IsPrimaryKey    = true;
					PrimaryKeyOrder = a.Order;
				}
			}

			if (DbType == null || DataType == DataType.Undefined)
			{
				var a = mappingSchema.GetAttribute<DataTypeAttribute>(MemberInfo, attr => attr.Configuration);

				if (a != null)
				{
					if (DbType == null)
						DbType = a.DbType;

					if (DataType == DataType.Undefined && a.DataType.HasValue)
						DataType = a.DataType.Value;
				}
			}
		}
コード例 #6
0
ファイル: ColumnDescriptor.cs プロジェクト: ru-sh/linq2db
        public ColumnDescriptor(MappingSchema mappingSchema, ColumnAttribute columnAttribute, MemberAccessor memberAccessor)
        {
            MappingSchema  = mappingSchema;
            MemberAccessor = memberAccessor;
            MemberInfo     = memberAccessor.MemberInfo;

            if (MemberInfo.IsFieldEx())
            {
                var fieldInfo = (FieldInfo)MemberInfo;
                MemberType = fieldInfo.FieldType;
            }
            else if (MemberInfo.IsPropertyEx())
            {
                var propertyInfo = (PropertyInfo)MemberInfo;
                MemberType = propertyInfo.PropertyType;
            }

            MemberName      = columnAttribute.MemberName ?? MemberInfo.Name;
            ColumnName      = columnAttribute.Name       ?? MemberInfo.Name;
            Storage         = columnAttribute.Storage;
            PrimaryKeyOrder = columnAttribute.PrimaryKeyOrder;
            IsDiscriminator = columnAttribute.IsDiscriminator;
            DataType        = columnAttribute.DataType;
            DbType          = columnAttribute.DbType;

            if (columnAttribute.HasLength   ()) Length    = columnAttribute.Length;
            if (columnAttribute.HasPrecision()) Precision = columnAttribute.Precision;
            if (columnAttribute.HasScale    ()) Scale     =  columnAttribute.Scale;

            var defaultCanBeNull = false;

            if (columnAttribute.HasCanBeNull())
                CanBeNull = columnAttribute.CanBeNull;
            else
            {
                var na = mappingSchema.GetAttribute<NullableAttribute>(MemberInfo, attr => attr.Configuration);

                if (na != null)
                {
                    CanBeNull = na.CanBeNull;
                }
                else
                {
                    CanBeNull        = mappingSchema.GetCanBeNull(MemberType);
                    defaultCanBeNull = true;
                }
            }

            if (columnAttribute.HasIsIdentity())
                IsIdentity = columnAttribute.IsIdentity;
            else
            {
                var a = mappingSchema.GetAttribute<IdentityAttribute>(MemberInfo, attr => attr.Configuration);
                if (a != null)
                    IsIdentity = true;
            }

            SkipOnInsert = columnAttribute.HasSkipOnInsert() ? columnAttribute.SkipOnInsert : IsIdentity;
            SkipOnUpdate = columnAttribute.HasSkipOnUpdate() ? columnAttribute.SkipOnUpdate : IsIdentity;

            if (defaultCanBeNull && IsIdentity)
                CanBeNull = false;

            if (columnAttribute.HasIsPrimaryKey())
                IsPrimaryKey = columnAttribute.IsPrimaryKey;
            else
            {
                var a = mappingSchema.GetAttribute<PrimaryKeyAttribute>(MemberInfo, attr => attr.Configuration);

                if (a != null)
                {
                    IsPrimaryKey    = true;
                    PrimaryKeyOrder = a.Order;
                }
            }
        }