示例#1
0
        private List <ColumnWrapper> GetSortedColumnsForMobile(Type type, DataTable data)
        {
            int num;
            List <ColumnWrapper> list = new List <ColumnWrapper>();
            Table tableOrCreate       = TableCache.GetTableOrCreate(type);

            foreach (Column column in tableOrCreate.KeyColumns)
            {
                num = data.Columns.IndexOf(column.ColumnName);
                if (num >= 0)
                {
                    list.Add(new ColumnWrapper(num, column));
                }
            }
            IEnumerable <Column> enumerable = from p in tableOrCreate.NonKeyColumns
                                              where p.ColumnName != "State"
                                              select p;

            foreach (Column column in enumerable)
            {
                num = data.Columns.IndexOf(column.ColumnName);
                if (num >= 0)
                {
                    list.Add(new ColumnWrapper(num, column));
                }
            }
            Column columnByColumnName = tableOrCreate.GetColumnByColumnName("State");
            int    index = data.Columns.IndexOf("State");

            if (index >= 0)
            {
                list.Add(new ColumnWrapper(index, columnByColumnName));
            }
            return(list);
        }
示例#2
0
 public void AppendTable(Type type, IList <DataRow> list)
 {
     if ((list != null) && (list.Count > 0))
     {
         Table tableOrCreate = TableCache.GetTableOrCreate(type);
         List <ColumnWrapper> sortedColumnsForMobile = this.GetSortedColumnsForMobile(type, list[0].Table);
         this.Append(tableOrCreate.TableName);
         this.AppendSplitter();
         this.AppendLine(list.Count);
         int num = -1;
         foreach (ColumnWrapper wrapper in sortedColumnsForMobile)
         {
             num++;
             if (num > 0)
             {
                 this.sb.Append(',');
             }
             EncodeAndAppend(this.sb, wrapper.col.ColumnName);
         }
         this.sb.Append('\n');
         foreach (DataRow row in list)
         {
             num = -1;
             foreach (ColumnWrapper wrapper in sortedColumnsForMobile)
             {
                 num++;
                 if (num > 0)
                 {
                     this.sb.Append(',');
                 }
                 if (row.IsNull(wrapper.Index))
                 {
                     wrapper.col.TypeHelper.EncodeInto(this.sb, null);
                 }
                 else
                 {
                     object obj2 = row[wrapper.Index];
                     wrapper.col.TypeHelper.EncodeInto(this.sb, obj2);
                 }
             }
             this.sb.Append('\n');
         }
     }
 }
示例#3
0
        private List <ColumnWrapper> GetSortedColumnsForMobile(Type type, IDataReader data)
        {
            int ordinal;
            List <ColumnWrapper> list = new List <ColumnWrapper>();
            Table tableOrCreate       = TableCache.GetTableOrCreate(type);

            foreach (Column column in tableOrCreate.KeyColumns)
            {
                ordinal = data.GetOrdinal(column.ColumnName);
                if (ordinal >= 0)
                {
                    list.Add(new ColumnWrapper(ordinal, column));
                }
            }
            IEnumerable <Column> enumerable = from p in tableOrCreate.NonKeyColumns
                                              where p.ColumnName != "State"
                                              select p;

            foreach (Column column in enumerable)
            {
                ordinal = data.GetOrdinal(column.ColumnName);
                if (ordinal >= 0)
                {
                    list.Add(new ColumnWrapper(ordinal, column));
                }
            }
            try
            {
                Column columnByColumnName = tableOrCreate.GetColumnByColumnName("State");
                int    index = data.GetOrdinal("State");
                if (index >= 0)
                {
                    list.Add(new ColumnWrapper(index, columnByColumnName));
                }
            }
            catch
            {
            }
            return(list);
        }
示例#4
0
 public void AppendTable(IList list)
 {
     if (list != null)
     {
         Table tableOrCreate = TableCache.GetTableOrCreate(TypeSystem.GetElementType(list.GetType()));
         this.Append(tableOrCreate.TableName);
         this.AppendSplitter();
         this.AppendLine(list.Count);
         int num = -1;
         foreach (Column column in tableOrCreate.KeyColumns)
         {
             num++;
             if (num > 0)
             {
                 this.sb.Append(',');
             }
             EncodeAndAppend(this.sb, column.ColumnName);
         }
         Column column2 = tableOrCreate.NonKeyColumns.FirstOrDefault <Column>(p => p.ColumnName == "State");
         foreach (Column column in from p in tableOrCreate.NonKeyColumns
                  where p.ColumnName != "State"
                  select p)
         {
             num++;
             if (num > 0)
             {
                 this.sb.Append(',');
             }
             EncodeAndAppend(this.sb, column.ColumnName);
         }
         if (column2 != null)
         {
             num++;
             if (num > 0)
             {
                 this.sb.Append(',');
             }
             EncodeAndAppend(this.sb, column2.ColumnName);
         }
         this.sb.Append('\n');
         foreach (object obj2 in list)
         {
             object obj3;
             num = -1;
             foreach (Column column in tableOrCreate.KeyColumns)
             {
                 num++;
                 if (num > 0)
                 {
                     this.sb.Append(',');
                 }
                 obj3 = column.GetFunction(obj2);
                 column.TypeHelper.EncodeInto(this.sb, obj3);
             }
             foreach (Column column in from p in tableOrCreate.NonKeyColumns
                      where p.ColumnName != "State"
                      select p)
             {
                 num++;
                 if (num > 0)
                 {
                     this.sb.Append(',');
                 }
                 obj3 = column.GetFunction(obj2);
                 column.TypeHelper.EncodeInto(this.sb, obj3);
             }
             if (column2 != null)
             {
                 num++;
                 if (num > 0)
                 {
                     this.sb.Append(',');
                 }
                 obj3 = column2.GetFunction(obj2);
                 column2.TypeHelper.EncodeInto(this.sb, obj3);
             }
             this.sb.Append('\n');
         }
     }
 }
示例#5
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();
        }