예제 #1
0
            public Column(PropertyInfo prop, CreateFlags createFlags = CreateFlags.None)
            {
                var colAttr = prop.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(ColumnAttribute));

                _prop = prop;
                Name  = (colAttr != null && colAttr.ConstructorArguments.Count > 0) ?
                        colAttr.ConstructorArguments [0].Value?.ToString() :
                        prop.Name;
                //If this type is Nullable<T> then Nullable.GetUnderlyingType returns the T, otherwise it returns null, so get the actual type instead
                ColumnType = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
                Collation  = Orm.Collation(prop);

                IsPK = Orm.IsPK(prop) ||
                       (((createFlags & CreateFlags.ImplicitPK) == CreateFlags.ImplicitPK) &&
                        string.Compare(prop.Name, Orm.ImplicitPkName, StringComparison.OrdinalIgnoreCase) == 0);

                var isAuto = Orm.IsAutoInc(prop) || (IsPK && ((createFlags & CreateFlags.AutoIncPK) == CreateFlags.AutoIncPK));

                IsAutoGuid = isAuto && ColumnType == typeof(Guid);
                IsAutoInc  = isAuto && !IsAutoGuid;

                Indices = Orm.GetIndices(prop);
                if (!Indices.Any() &&
                    !IsPK &&
                    ((createFlags & CreateFlags.ImplicitIndex) == CreateFlags.ImplicitIndex) &&
                    Name.EndsWith(Orm.ImplicitIndexSuffix, StringComparison.OrdinalIgnoreCase)
                    )
                {
                    Indices = new IndexedAttribute [] { new IndexedAttribute() };
                }
                IsNullable      = !(IsPK || Orm.IsMarkedNotNull(prop));
                MaxStringLength = Orm.MaxStringLength(prop);

                StoreAsText = prop.PropertyType.GetTypeInfo().CustomAttributes.Any(x => x.AttributeType == typeof(StoreAsTextAttribute));
            }
예제 #2
0
            public Column(PropertyInfo prop, CreateFlags createFlags = CreateFlags.None)
            {
                var colAttr = (ColumnAttribute)prop.GetCustomAttributes(typeof(ColumnAttribute), true).FirstOrDefault();

                _prop = prop;
                Name  = colAttr == null ? prop.Name : colAttr.Name;
                //If this type is Nullable<T> then Nullable.GetUnderlyingType returns the T, otherwise it returns null, so get the actual type instead

                if (prop.PropertyType is ILRuntimeType)
                {
                    ColumnType = prop.PropertyType;
                }
                else
                {
                    ColumnType = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
                }

                Collation = Orm.Collation(prop);

                IsPK = Orm.IsPK(prop) || (((createFlags & CreateFlags.ImplicitPK) == CreateFlags.ImplicitPK) && string.Compare(prop.Name, Orm.ImplicitPkName, StringComparison.OrdinalIgnoreCase) == 0);

                var isAuto = Orm.IsAutoInc(prop) || (IsPK && ((createFlags & CreateFlags.AutoIncPK) == CreateFlags.AutoIncPK));

                IsAutoGuid = isAuto && ColumnType == typeof(Guid);
                IsAutoInc  = isAuto && !IsAutoGuid;

                Indices = Orm.GetIndices(prop);
                if (!Indices.Any() && !IsPK && ((createFlags & CreateFlags.ImplicitIndex) == CreateFlags.ImplicitIndex) && Name.EndsWith(Orm.ImplicitIndexSuffix, StringComparison.OrdinalIgnoreCase))
                {
                    Indices = new IndexedAttribute[] { new IndexedAttribute() };
                }

                IsNullable      = !(IsPK || Orm.IsMarkedNotNull(prop));
                MaxStringLength = Orm.MaxStringLength(prop);
            }
예제 #3
0
            public Column(PropertyInfo prop)
            {
                var colAttr = (ColumnAttribute)prop.GetCustomAttributes(typeof(ColumnAttribute), true).FirstOrDefault();

                _prop = prop;
                Name  = colAttr == null ? prop.Name : colAttr.Name;
                //If this type is Nullable<T> then Nullable.GetUnderlyingType returns the T, otherwise it returns null, so get the actual type instead
                ColumnType = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
                Collation  = Orm.Collation(prop);

                IsPK = Orm.IsPK(prop);

                var isAuto = Orm.IsAutoInc(prop);

                IsAutoGuid = isAuto && ColumnType == typeof(Guid);
                IsAutoInc  = isAuto && !IsAutoGuid;

                Indices = Orm.GetIndices(prop);
                if (!Indices.Any() &&
                    !IsPK &&
                    Name.EndsWith(Orm.ImplicitIndexSuffix, StringComparison.OrdinalIgnoreCase)
                    )
                {
                    Indices = new[] { new IndexedAttribute() };
                }
                IsNullable      = !IsPK;
                MaxStringLength = Orm.MaxStringLength(prop);
            }
        protected AbstractDirectTableMappingColumn(MemberInfo info, string path, CreateFlags createFlags = CreateFlags.None)
            : base(info, path, createFlags)
        {
            Collation = ORMUtilities.Collation(info);

            IsPK = ORMUtilities.IsPrimaryKey(info) ||
                   (((createFlags & CreateFlags.ImplicitPK) == CreateFlags.ImplicitPK) &&
                    string.Compare(info.Name, ORMUtilities.ImplicitPkName, StringComparison.OrdinalIgnoreCase) == 0);

            var isAuto = ORMUtilities.IsAutoInc(info) || (IsPK && ((createFlags & CreateFlags.AutoIncPK) == CreateFlags.AutoIncPK));

            IsAutoGuid = isAuto && TargetType == typeof(Guid);
            IsAutoInc  = isAuto && !IsAutoGuid;

            if (!Indices.Any() &&
                !IsPK &&
                ((createFlags & CreateFlags.ImplicitIndex) == CreateFlags.ImplicitIndex) &&
                Name.EndsWith(ORMUtilities.ImplicitIndexSuffix, StringComparison.OrdinalIgnoreCase)
                )
            {
                Indices = new IndexedAttribute[] { new IndexedAttribute() };
            }
            IsNullable      = !(IsPK || ORMUtilities.IsMarkedNotNull(info));
            MaxStringLength = ORMUtilities.MaxStringLength(info);
            TargetName      = info.Name;
        }
예제 #5
0
            public Column(PropertyInfo prop, CreateFlags createFlags = CreateFlags.None, IColumnInformationProvider infoProvider = null)
            {
                infoProvider ??= new DefaultColumnInformationProvider();

                _prop = prop;
                Name  = infoProvider.GetColumnName(prop);
                //If this type is Nullable<T> then Nullable.GetUnderlyingType returns the T, otherwise it returns null, so get the actual type instead
                ColumnType = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
                Collation  = Orm.Collation(prop);

                IsPK = Orm.IsPK(prop) ||
                       (((createFlags & CreateFlags.ImplicitPK) == CreateFlags.ImplicitPK) &&
                        string.Compare(prop.Name, Orm.ImplicitPkName, StringComparison.OrdinalIgnoreCase) == 0);

                var isAuto = Orm.IsAutoInc(prop) ||
                             (IsPK && ((createFlags & CreateFlags.AutoIncPK) == CreateFlags.AutoIncPK));

                IsAutoGuid = isAuto && ColumnType == typeof(Guid);
                IsAutoInc  = isAuto && !IsAutoGuid;

                DefaultValue = Orm.GetDefaultValue(prop);

                Indices = Orm.GetIndices(prop);
                if (!Indices.Any() &&
                    !IsPK &&
                    ((createFlags & CreateFlags.ImplicitIndex) == CreateFlags.ImplicitIndex) &&
                    Name.EndsWith(Orm.ImplicitIndexSuffix, StringComparison.OrdinalIgnoreCase))
                {
                    Indices = new[] { new IndexedAttribute() };
                }
                IsNullable      = !(IsPK || Orm.IsMarkedNotNull(prop));
                MaxStringLength = Orm.MaxStringLength(prop);
            }
예제 #6
0
        public TableColumn(PropertyInfo prop, Action <PropertyInfo, object, object> setValue, Func <PropertyInfo, object, object> getValue, CreateFlags createFlags)
        {
            const string ImplicitPkName      = "Id";
            const string ImplicitIndexSuffix = "Id";

            var colAttr = (ColumnAttribute)prop.GetCustomAttributes(typeof(ColumnAttribute), true).FirstOrDefault();

            _prop        = prop;
            PropertyName = prop.Name;
            PropertyType = prop.PropertyType;

            var propertyTypeInfo = PropertyType.GetTypeInfo();

            PropertyDefaultValue = (PropertyType != null && propertyTypeInfo.IsValueType && Nullable.GetUnderlyingType(PropertyType) == null) ? Activator.CreateInstance(PropertyType) : null;

            _setValue = setValue;
            _getValue = getValue;

            Name = colAttr == null ? prop.Name : colAttr.Name;
            //If this type is Nullable<T> then Nullable.GetUnderlyingType returns the T, otherwise it returns null, so get the actual type instead
            ColumnType = Nullable.GetUnderlyingType(PropertyType) ?? PropertyType;

            var columnTypeInfo = ColumnType.GetTypeInfo();

            IsEnum = columnTypeInfo.IsEnum;

            var attr = prop.GetCustomAttributes(true);

            Collation = attr.OfType <CollationAttribute>().FirstOrDefault()?.Value ?? "";

            IsPK = attr.OfType <PrimaryKeyAttribute>().Any() || (createFlags.HasFlag(CreateFlags.ImplicitPK) && String.Equals(prop.Name, ImplicitPkName, StringComparison.OrdinalIgnoreCase));

            var isAuto = attr.OfType <AutoIncrementAttribute>().Any() || (IsPK && createFlags.HasFlag(CreateFlags.AutoIncPK));

            IsAutoGuid = isAuto && ColumnType == typeof(Guid);
            IsAutoInc  = isAuto && !IsAutoGuid;

            Indices = attr.OfType <IndexedAttribute>();

            if (!Indices.Any() &&
                !IsPK &&
                createFlags.HasFlag(CreateFlags.ImplicitIndex) &&
                Name.EndsWith(ImplicitIndexSuffix, StringComparison.OrdinalIgnoreCase)
                )
            {
                Indices = new IndexedAttribute[] { new IndexedAttribute() };
            }
            IsNullable = !(IsPK || attr.OfType <NotNullAttribute>().Any());

            MaxStringLength = attr.OfType <MaxLengthAttribute>().FirstOrDefault()?.Value;
            DefaultValue    = attr.OfType <DefaultAttribute>().FirstOrDefault()?.Value;
            StoreAsText     = attr.OfType <StoreAsTextAttribute>().Any();
        }
예제 #7
0
            public Column(PropertyInfo prop, CreateFlags createFlags = CreateFlags.None)
            {
                var colAttr = (ColumnAttribute)prop.GetCustomAttributes(typeof(ColumnAttribute), true).FirstOrDefault();

                _prop = prop;
                Name  = colAttr == null ? prop.Name : colAttr.Name;
                //If this type is Nullable<T> then Nullable.GetUnderlyingType returns the T, otherwise it returns null, so get the actual type instead
                ColumnType = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
                Collation  = Orm.Collation(prop);

                IsPK = Orm.IsPK(prop) ||
                       (((createFlags & CreateFlags.ImplicitPK) == CreateFlags.ImplicitPK) &&
                        string.Compare(prop.Name, Orm.ImplicitPkName, StringComparison.OrdinalIgnoreCase) == 0);

                IsCK = Orm.IsCK(prop);

                IsFK = Orm.IsFK(prop);
                if (IsFK)
                {
                    ForeignKeyAttribute attr     = prop.GetCustomAttribute <ForeignKeyAttribute>(true);
                    TableMapping        refTable = new TableMapping(attr.ReferenceTable);
                    string refColumnName         = attr.ReferenceColumn ?? this.Name;
                    var    refColumns            = refTable.Columns.Select(c => c).Where(c => c.Name == refColumnName).ToArray();
                    if (refColumns.Length > 0)
                    {
                        FK = new ForeignKey(this, attr.ReferenceTable, refColumns[0]);
                    }
                    else
                    {
                        throw new Exception(string.Format("The referenced column \"{0}\" in {1} doesn't exist", refColumnName, this.Name));
                    }
                }

                var isAuto = Orm.IsAutoInc(prop) || (IsPK && ((createFlags & CreateFlags.AutoIncPK) == CreateFlags.AutoIncPK));

                IsAutoGuid = isAuto && ColumnType == typeof(Guid);
                IsAutoInc  = isAuto && !IsAutoGuid;

                Indices = Orm.GetIndices(prop);
                if (!Indices.Any() &&
                    !IsPK &&
                    ((createFlags & CreateFlags.ImplicitIndex) == CreateFlags.ImplicitIndex) &&
                    Name.EndsWith(Orm.ImplicitIndexSuffix, StringComparison.OrdinalIgnoreCase)
                    )
                {
                    Indices = new IndexedAttribute[] { new IndexedAttribute() };
                }
                IsNullable      = !(IsPK || Orm.IsMarkedNotNull(prop));
                MaxStringLength = Orm.MaxStringLength(prop);

                StoreAsText = prop.PropertyType.GetTypeInfo().GetCustomAttribute(typeof(StoreAsTextAttribute), false) != null;
            }
예제 #8
0
        public virtual void AddIndex(SQLiteObjectIndex index)
        {
            if (index == null)
            {
                throw new ArgumentNullException(nameof(index));
            }

            if (Indices.Any(c => c.Name.EqualsIgnoreCase(index.Name)))
            {
                throw new SqlNadoException("0027: There is already a '" + index.Name + "' index in the '" + Name + "' table.");
            }

            _indices.Add(index);
        }
예제 #9
0
        /// <summary>
        /// Adds the index.
        /// </summary>
        /// <param name="mnemonic">The mnemonic.</param>
        /// <param name="unit">The unit.</param>
        /// <param name="dataType">The data type.</param>
        /// <param name="increasing">if set to <c>true</c> if data is incresting, false otherwise.</param>
        /// <param name="isTimeIndex">if set to <c>true</c> if index is time, false otherwise.</param>
        /// <param name="nullValue">The null value.</param>
        public void AddIndex(string mnemonic, string unit, string dataType, bool increasing, bool isTimeIndex, string nullValue = null)
        {
            if (Indices.Any(x => x.Mnemonic.EqualsIgnoreCase(mnemonic)))
            {
                return;
            }

            Indices.Add(new ChannelIndexInfo()
            {
                Mnemonic    = mnemonic,
                Increasing  = increasing,
                IsTimeIndex = isTimeIndex,
                Unit        = unit,
                DataType    = dataType,
                NullValue   = nullValue
            });
        }
예제 #10
0
            public Column(PropertyInfo prop, CreateFlags createFlags = CreateFlags.None)
            {
                var colAttr = (ColumnAttribute)prop.GetCustomAttributes(typeof(ColumnAttribute), true).FirstOrDefault();

                _prop = prop;
                Name  = colAttr == null ? prop.Name : (!string.IsNullOrEmpty(colAttr.Name) ? colAttr.Name : prop.Name);
                //If this type is Nullable<T> then Nullable.GetUnderlyingType returns the T, otherwise it returns null, so get the actual type instead
                ColumnType = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
                ValueType  = colAttr != null ? colAttr.ValueType : null;
                Collation  = Orm.Collation(prop);

                var pkOrder = 0;

                IsPK = Orm.IsPK(prop, out pkOrder) ||
                       (((createFlags & CreateFlags.ImplicitPK) == CreateFlags.ImplicitPK) &&
                        string.Compare(prop.Name, Orm.ImplicitPkName, StringComparison.OrdinalIgnoreCase) == 0);
                PKOrder = pkOrder;

                var isAuto = Orm.IsAutoInc(prop) || (IsPK && ((createFlags & CreateFlags.AutoIncPK) == CreateFlags.AutoIncPK));

                IsAutoGuid = isAuto && ColumnType == typeof(Guid);
                IsAutoInc  = isAuto && !IsAutoGuid;

                Indices = Orm.GetIndices(prop);
                if (!Indices.Any() &&
                    !IsPK &&
                    ((createFlags & CreateFlags.ImplicitIndex) == CreateFlags.ImplicitIndex) &&
                    Name.EndsWith(Orm.ImplicitIndexSuffix, StringComparison.OrdinalIgnoreCase)
                    )
                {
                    Indices = new IndexedAttribute[] { new IndexedAttribute() };
                }

                IsNullable      = !IsPK && !(colAttr != null && colAttr.IsNotNull);
                DefaultValue    = colAttr != null ? colAttr.DefaultValue : null;
                MaxStringLength = Orm.MaxStringLength(prop);
            }
예제 #11
0
            public Column(PropertyInfo prop, CreateFlags createFlags = CreateFlags.None)
            {
                ColumnAttribute columnAttribute = (ColumnAttribute)prop.GetCustomAttributes(typeof(ColumnAttribute), inherit: true).FirstOrDefault();

                _prop      = prop;
                Name       = ((columnAttribute != null) ? columnAttribute.Name : prop.Name);
                ColumnType = (Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
                Collation  = Orm.Collation(prop);
                IsPK       = (Orm.IsPK(prop) || ((createFlags & CreateFlags.ImplicitPK) == CreateFlags.ImplicitPK && string.Compare(prop.Name, "Id", StringComparison.OrdinalIgnoreCase) == 0));
                bool flag = Orm.IsAutoInc(prop) || (IsPK && (createFlags & CreateFlags.AutoIncPK) == CreateFlags.AutoIncPK);

                IsAutoGuid = (flag && ColumnType == typeof(Guid));
                IsAutoInc  = (flag && !IsAutoGuid);
                Indices    = Orm.GetIndices(prop);
                if (!Indices.Any() && !IsPK && (createFlags & CreateFlags.ImplicitIndex) == CreateFlags.ImplicitIndex && Name.EndsWith("Id", StringComparison.OrdinalIgnoreCase))
                {
                    Indices = new IndexedAttribute[1]
                    {
                        new IndexedAttribute()
                    };
                }
                IsNullable      = (!IsPK && !Orm.IsMarkedNotNull(prop));
                MaxStringLength = Orm.MaxStringLength(prop);
            }
예제 #12
0
 public bool CheckHasRoundEdgeData()
 {
     HasRoundEdgeData = Indices.Any(x => !x.RoundEdgeData.IsEmpty);
     return(HasRoundEdgeData);
 }
예제 #13
0
 public bool CheckIfRoundEdgaDataDefined()
 {
     return(Indices.Any(x => !x.RoundEdgeData.IsEmpty));
 }