예제 #1
0
        internal List <InternalColumnWrapper> GetSortedInternalColumnsForMobile(IDataReader data)
        {
            List <InternalColumnWrapper> list = new List <InternalColumnWrapper>(data.FieldCount);

            for (int i = 0; i < data.FieldCount; i++)
            {
                Type       fieldType       = data.GetFieldType(i);
                ISharpType shartTypeHelper = SharpTypeHelper.GetShartTypeHelper(fieldType);
                list[i] = new InternalColumnWrapper(i, fieldType, shartTypeHelper, data.GetName(i));
            }
            return(list);
        }
예제 #2
0
        internal List <InternalColumnWrapper> GetSortedInternalColumnsForMobile(DataTable data)
        {
            List <InternalColumnWrapper> list = new List <InternalColumnWrapper>(data.Columns.Count);

            for (int i = 0; i < data.Columns.Count; i++)
            {
                DataColumn column          = data.Columns[i];
                Type       dataType        = column.DataType;
                ISharpType shartTypeHelper = SharpTypeHelper.GetShartTypeHelper(dataType);
                list.Add(new InternalColumnWrapper(i, dataType, shartTypeHelper, column.ColumnName));
            }
            return(list);
        }
예제 #3
0
        private Table(Type type)
        {
            Column current;

            this._identityColumn     = null;
            this._tableVersionColumn = null;
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (!type.IsClass)
            {
                throw new ApplicationException("type is not a class");
            }
            object[] customAttributes = type.GetCustomAttributes(typeof(KingTableAttribute), false);
            if (customAttributes.Length > 0)
            {
                KingTableAttribute attribute = customAttributes[0] as KingTableAttribute;
                if (string.IsNullOrWhiteSpace(attribute.Name))
                {
                    this._tableName = type.Name;
                }
                else
                {
                    this._tableName = attribute.Name;
                }
                if (string.IsNullOrWhiteSpace(attribute.Schema))
                {
                    this._schemaName = "dbo";
                }
                else
                {
                    this._schemaName = attribute.Schema;
                }
                if (attribute.IsInherited)
                {
                    if (type.BaseType == typeof(object))
                    {
                        throw new ApplicationException(string.Format("标记为继承的实体类型{0}不能从object继承", type));
                    }
                    this._parentTable = TableCache.GetTableOrCreate(type.BaseType);
                }
            }
            else
            {
                this._tableName  = type.Name;
                this._schemaName = "dbo";
            }
            List <Column> source = new List <Column>();
            int           num    = 0;
            int           num2   = 0;

            if (this.ParentTable != null)
            {
                using (IEnumerator <Column> enumerator = this.ParentTable.KeyColumns.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        current = enumerator.Current;
                        Column item = GetColumn(current.PropertyInfo);
                        source.Add(item);
                    }
                }
                num2 += this.ParentTable.KeyColumns.Count;
                num  += this.ParentTable.KeyColumns.Count;
            }
            PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            foreach (PropertyInfo info in properties)
            {
                current = GetColumn(info);
                if (current != null)
                {
                    source.Add(current);
                    num++;
                    if (current.IsPrimaryKey)
                    {
                        num2++;
                    }
                }
            }
            if (num == 0)
            {
                throw new ApplicationException(string.Format("{0}未指定任何字段", type.Name));
            }
            if (num2 == 0)
            {
                string message = string.Format("{0}未指定义键", type.Name);
                Debug.WriteLine(message);
                Trace.WriteLine(message);
                throw new ApplicationException(message);
            }
            foreach (Column column in source)
            {
                column.TypeHelper  = SharpTypeHelper.GetShartTypeHelper(column.DataType);
                column.GetFunction = SharpTypeHelper.CreateGetFunction(type, column.PropertyInfo.Name);
                column.SetAction   = SharpTypeHelper.CreateSetAction(type, column.PropertyInfo.Name);
            }
            this._columns    = source.AsReadOnly();
            this._keyColumns = (from p in source
                                where p.IsPrimaryKey
                                orderby p.KeyOrder
                                select p).ToList <Column>().AsReadOnly();
            this._nonKeyColumns = (from p in source
                                   where !p.IsPrimaryKey
                                   select p).ToList <Column>().AsReadOnly();
            this._identityColumn     = source.FirstOrDefault <Column>(p => p.IsIdentity);
            this._nonIdentityColumns = (from p in source
                                        where !p.IsIdentity
                                        select p).ToList <Column>().AsReadOnly();
            this._propertyDict     = source.ToDictionary <Column, PropertyInfo>(p => p.PropertyInfo);
            this._propertyNameDict = source.ToDictionary <Column, string>(p => p.PropertyInfo.Name);
            this._columnDict       = source.ToDictionary <Column, string>(p => p.ColumnName.ToLower());
            this._keyMembers       = (from p in this._keyColumns select p.PropertyInfo).Cast <MemberInfo>().ToList <MemberInfo>().AsReadOnly();
            this._mappedMembers    = (from p in this._columns select p.PropertyInfo).Cast <MemberInfo>().ToList <MemberInfo>().AsReadOnly();
            this.InitSqlCache();
        }