Exemplo n.º 1
0
        //=========================================================================
        //  FunctionName : Initialize
        /// <summary>
        /// 初始化数据实体
        /// </summary>
        /// <remarks>
        /// 初始化数据实体实例
        /// </remarks>
        //=========================================================================
        private void Initialize()
        {
            lock (this.GetType())
            {
                string      className = this.GetType().ToString();
                IDictionary typeTable = DataTypeManager.GetTypeInfo(className);
                if (typeTable == null)
                {
                    Hashtable propertyTable = new Hashtable();

                    ColumnInfo     infoColumn;
                    string[]       columnList     = this.GetColumnName();
                    SqlDbType[]    columnTypeList = this.GetColumnType();
                    string[]       keyList        = this.GetPrimaryKey();
                    string[]       nullList       = this.GetNullableColumn();
                    PropertyInfo[] properties     = this.GetType().GetProperties();

                    for (int i = 0; i < columnList.Length; i++)
                    {
                        infoColumn                             = new ColumnInfo();
                        infoColumn.ColumnType                  = columnTypeList[i];
                        propertyTable[columnList[i]]           = infoColumn;
                        propertyTable[columnList[i].ToLower()] = infoColumn;
                    }

                    foreach (PropertyInfo infoProperty in properties)
                    {
                        infoColumn = (ColumnInfo)propertyTable[infoProperty.Name];
                        if (infoColumn == null)
                        {
                            continue;
                        }

                        infoColumn.ColumnProperty = infoProperty;
                        if (keyList.Any(keyCol => keyCol == infoProperty.Name))
                        {
                            infoColumn.IsPrimaryKey = true;
                        }
                        if (nullList.Any(nullCol => nullCol == infoProperty.Name))
                        {
                            infoColumn.IsNullable = true;
                        }
                    }

                    DataTypeManager.SetTypeInfo(className, propertyTable);
                }
            }
        }