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; } }
/// <summary> /// 转换为SourceTable /// </summary> /// <returns></returns> public SourceTable ToTable() { var sourceTable = new SourceTable(); sourceTable.Load(reader); reader.Close(); reader.Dispose(); return(sourceTable); }
/// <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); } } }
/// <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); }
/// <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; }
/// <summary> /// 实例化填充关系 /// </summary> /// <param name="source"></param> /// <param name="relationName"></param> public FillRelation(SourceTable source, string relationName) : this(source, relationName, relationName) { }