示例#1
0
        private SourceTable ExecuteDataTable <TResult>(QuerySection <TResult> query)
            where TResult : Entity
        {
            try
            {
                string queryString = query.QueryString;
                string cacheKey    = GetCacheKey(queryString, query.Parameters);
                object obj         = GetCache <TResult>("DataTable", cacheKey);
                if (obj != null)
                {
                    return((SourceTable)obj);
                }

                //添加参数到Command中
                queryCommand = dbProvider.CreateSqlCommand(queryString, query.Parameters);

                using (DataTable dataTable = dbProvider.ExecuteDataTable(queryCommand, dbTran))
                {
                    dataTable.TableName = typeof(TResult).Name;
                    SourceTable table = new SourceTable(dataTable);

                    SetCache <TResult>("DataTable", cacheKey, table);

                    return(table);
                }
            }
            catch
            {
                throw;
            }
        }
示例#2
0
        /// <summary>
        /// 转换为SourceTable
        /// </summary>
        /// <returns></returns>
        public SourceTable ToTable()
        {
            var sourceTable = new SourceTable();

            sourceTable.Load(reader);
            reader.Close();
            reader.Dispose();

            return(sourceTable);
        }
示例#3
0
        /// <summary>
        /// 返回一个行阅读对象
        /// </summary>
        IRowReader IEntityBase.ToRowReader()
        {
            lock (this)
            {
                try
                {
                    SourceList <EntityBase> list = new SourceList <EntityBase>();
                    list.Add(this);

                    DataTable    dt    = list.GetDataTable(this.GetType());
                    ISourceTable table = new SourceTable(dt);
                    return(table[0]);
                }
                catch (Exception ex)
                {
                    throw new DataException("数据转换失败!", ex);
                }
            }
        }
示例#4
0
        /// <summary>
        /// 选择某些列
        /// </summary>
        /// <param name="names"></param>
        /// <returns></returns>
        public SourceTable Select(params string[] names)
        {
            SourceTable   st       = this.Clone();
            List <string> namelist = new List <string>(names);

            namelist.ForEach(p => p.ToLower());
            foreach (DataColumn column in this.Columns)
            {
                if (!namelist.Contains(column.ColumnName.ToLower()))
                {
                    st.Columns.Remove(column.ColumnName);
                }
            }

            int index = 0;

            namelist.ForEach(p => st.Columns[p].SetOrdinal(index++));

            return(st);
        }
示例#5
0
 /// <summary>
 /// 实例化填充关系
 /// </summary>
 /// <param name="source"></param>
 /// <param name="relationName"></param>
 public FillRelation(SourceTable source, string parentName, string childName)
 {
     this.DataSource = source;
     this.ParentName = parentName;
     this.ChildName  = childName;
 }
示例#6
0
 /// <summary>
 /// 实例化填充关系
 /// </summary>
 /// <param name="source"></param>
 /// <param name="relationName"></param>
 public FillRelation(SourceTable source, string relationName)
     : this(source, relationName, relationName)
 {
 }