Esempio n. 1
0
 /// <summary>
 ///		Create instance of ModelColumnMap
 /// </summary>
 /// <param name="field">
 ///		The reflection information about the model's field
 /// </param>
 /// <param name="colAttr">
 ///		The column attribute associated with the field
 /// </param>
 public ModelColumnMap(FieldInfo field, ColumnMappingAttribute colAttr)
 {
     this.field           = field;
     this.columnAttribute = colAttr;
     this.isDbTypeNull    = false;
     if (!colAttr.IsDatabaseTypeNull)
     {
         this.dbType = colAttr.DatabaseType;
     }
     else
     {
         if (field.FieldType == typeof(int))
         {
             // field.FieldType == typeof(IntClass) ||
             this.dbType = DbType.Int32;
         }
         else if (field.FieldType == typeof(DateTime))
         {
             // field.FieldType == typeof(DateClass) ||
             this.dbType = DbType.DateTime;
         }
         else if (field.FieldType == typeof(string))
         {
             this.dbType = DbType.String;
         }
         else if (field.FieldType == typeof(bool))
         {
             this.dbType = DbType.Boolean;
         }
         else
         {
             this.isDbTypeNull = true;
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        ///		Set table attribute.
        /// </summary>
        private void SetTableAttribute()
        {
            object[] mappings;
            mappings = this.modelType.GetCustomAttributes(typeof(TableMappingAttribute), true);

            if (mappings != null && mappings.Length > 0)
            {
                this.tableAttribute = (TableMappingAttribute)mappings[0];

                if (this.tableAttribute.KeyFieldName != null)
                {
                    // Todo: uncomment when use filed mapping
                    // this.keyField = this.modelType.GetField(
                    //    this.tableAttribute.KeyFieldName,
                    //    BindingFlags.SuppressChangeType | BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                    // if (this.KeyField == null)
                    // {
                    //    this.keyProperty = this.modelType.GetProperty(this.tableAttribute.KeyFieldName);
                    // }
                    this.keyProperty = this.modelType.GetProperty(this.tableAttribute.KeyFieldName);
                }

                if (this.keyField != null || this.keyProperty != null)
                {
                    // Todo: uncomment when use filed mapping
                    // if (this.KeyField != null)
                    // {
                    //    mappings = this.keyField.GetCustomAttributes(typeof(ColumnMappingAttribute), true);
                    // }
                    // else if (this.keyProperty != null)
                    // {
                    //    mappings = this.keyProperty.GetCustomAttributes(typeof(ColumnMappingAttribute), true);
                    // }
                    mappings = this.keyProperty.GetCustomAttributes(typeof(ColumnMappingAttribute), true);

                    ColumnMappingAttribute attr = (ColumnMappingAttribute)mappings[0];
                    this.keyColumn = attr.ColumnName;
                }
                else
                {
                    this.keyColumn = this.tableAttribute.KeyFieldName;
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        ///		Create instance of ModelColumnMap
        /// </summary>
        /// <param name="property">
        ///		The reflection information about the model's property
        /// </param>
        /// <param name="colAttr">
        ///		The column attribute associated with the field
        /// </param>
        public ModelColumnMap(PropertyInfo property, ColumnMappingAttribute colAttr)
        {
            this.property        = property;
            this.columnAttribute = colAttr;
            this.isDbTypeNull    = false;

            if (!colAttr.IsDatabaseTypeNull)
            {
                this.dbType = colAttr.DatabaseType;
            }
            else
            {
                if (property.PropertyType == typeof(int))
                {
                    // property.PropertyType  == typeof(IntClass) ||
                    this.dbType = DbType.Int32;
                }
                else if (property.PropertyType == typeof(DateTime))
                {
                    // property.PropertyType == typeof(DateClass) ||
                    this.dbType = DbType.DateTime;
                }
                else if (property.PropertyType == typeof(string))
                {
                    this.dbType = DbType.String;
                }
                else if (property.PropertyType == typeof(bool))
                {
                    this.dbType = DbType.Boolean;
                }
                else
                {
                    this.isDbTypeNull = true;
                }
            }
        }