/// <summary> /// 在内存中对 IDataReader 进行读取。 /// 注意!!! /// 此方法中会释放 Reader。外层不能再用 Using。 /// </summary> /// <param name="reader">表格类数据。</param> /// <param name="readType">是否索引还是名称去读取 IDataReader。</param> /// <param name="list">需要把读取的实体,加入到这个列表中。</param> /// <param name="fetchingFirst">是否只读取一条数据即返回。</param> /// <param name="pagingInfo">如果不是只取一行数据,则这个参数表示列表内存分页的信息。</param> /// <param name="markTreeFullLoaded">如果某次查询结果是一棵完整的子树,那么必须设置此参数为 true ,才可以把整个树标记为完整加载。</param> protected void FillDataIntoList( IDataReader reader, ReadDataType readType, IList<Entity> list, bool fetchingFirst, PagingInfo pagingInfo, bool markTreeFullLoaded ) { if (_repository.SupportTree) { this.FillTreeIntoList(reader, readType, list, markTreeFullLoaded, pagingInfo); return; } //如果正在分页,而且支持数据库层面的分页,则不使用内存分页。 if (!PagingInfo.IsNullOrEmpty(pagingInfo) && this.GetPagingLocation(pagingInfo) == PagingLocation.Database) { pagingInfo = null; } var entityReader = CreateEntityReader(readType); Action<IDataReader> rowReader = dr => { var entity = entityReader.Read(dr); list.Add(entity); }; if (fetchingFirst) { if (reader.Read()) { rowReader(reader); } } else { PagingHelper.MemoryPaging(reader, rowReader, pagingInfo); } }
/// <summary> /// 在内存中对 IDataReader 进行读取,并以树的方式进行节点的加载。 /// </summary> /// <param name="reader">表格类数据。</param> /// <param name="readType">是否索引还是名称去读取 IDataReader。</param> /// <param name="list">需要把读取的实体中的第一级的节点,加入到这个列表中。</param> /// <param name="markTreeFullLoaded">如果某次查询结果是一棵完整的子树,那么必须设置此参数为 true ,才可以把整个树标记为完整加载。</param> /// <param name="pagingInfo">对根节点进行分页的信息。</param> private void FillTreeIntoList( IDataReader reader, ReadDataType readType, IList <Entity> list, bool markTreeFullLoaded, PagingInfo pagingInfo) { var entities = this.ReadToEntity(reader, readType); if (PagingInfo.IsNullOrEmpty(pagingInfo)) { TreeHelper.LoadTreeData(list, entities, _repository.TreeIndexOption); } else { //在内存中分页。 var tempList = new List <Entity>(); TreeHelper.LoadTreeData(tempList, entities, _repository.TreeIndexOption); var paged = tempList.JumpToPage(pagingInfo); foreach (var item in paged) { list.Add(item); } } if (markTreeFullLoaded) { TreeHelper.MarkTreeFullLoaded(list); } }
private IEnumerable <Entity> ReadToEntity(IDataReader reader, ReadDataType readType) { var entityReader = this.CreateEntityReader(readType); while (reader.Read()) { var entity = entityReader.Read(reader); yield return(entity); } }
private IEnumerable <Entity> ReadToEntity(IDataReader reader, ReadDataType readType) { var readByIndex = readType == ReadDataType.ByIndex; //最后一次添加的节点。 while (reader.Read()) { var entity = readByIndex ? this.CreateByIndex(reader) : this.CreateByName(reader); yield return(entity); } }
private EntityReader CreateEntityReader(ReadDataType readType) { if (_createByIndexReader == null) { _createByIndexReader = new CreateByIndexReader { _owner = this }; } return readType == ReadDataType.ByIndex ? _createByIndexReader ://可以缓存。 new CreateByNameReader { _owner = this };//CreateByNameReader 由于每个 SQL 的列的顺序不一定一致,所以不能进行缓存。 }
/// <summary> /// 执行 Sql 并读取 DataReader 中的值到实体。 /// </summary> /// <param name="dba">The dba.</param> /// <param name="args">The arguments.</param> /// <param name="readType">Type of the read.</param> /// <param name="sql">The SQL.</param> protected void QueryDataReader(IDbAccesser dba, IEntitySelectArgs args, ReadDataType readType, FormattedSql sql) { //查询数据库 using (var reader = dba.QueryDataReader(sql, sql.Parameters)) { //填充到列表中。 this.FillDataIntoList( reader, readType, args.List, args.FetchingFirst, args.PagingInfo, args.MarkTreeFullLoaded ); } }
private IEnumerable<Entity> ReadToEntity(IDataReader reader, ReadDataType readType) { var readByIndex = readType == ReadDataType.ByIndex; //最后一次添加的节点。 while (reader.Read()) { var entity = readByIndex ? this.CreateByIndex(reader) : this.CreateByName(reader); yield return entity; } }
/// <summary> /// 在内存中对 IDataReader 进行读取,并以树的方式进行节点的加载。 /// </summary> /// <param name="reader">表格类数据。</param> /// <param name="readType">是否索引还是名称去读取 IDataReader。</param> /// <param name="list">需要把读取的实体中的第一级的节点,加入到这个列表中。</param> /// <param name="markTreeFullLoaded">如果某次查询结果是一棵完整的子树,那么必须设置此参数为 true ,才可以把整个树标记为完整加载。</param> /// <param name="pagingInfo">对根节点进行分页的信息。</param> private void FillTreeIntoList( IDataReader reader, ReadDataType readType, IList<Entity> list, bool markTreeFullLoaded, PagingInfo pagingInfo) { var entities = this.ReadToEntity(reader, readType); if (PagingInfo.IsNullOrEmpty(pagingInfo)) { TreeHelper.LoadTreeData(list, entities, _repository.TreeIndexOption); } else { //在内存中分页。 var tempList =new List<Entity>(); TreeHelper.LoadTreeData(tempList, entities, _repository.TreeIndexOption); var paged = tempList.JumpToPage(pagingInfo); foreach (var item in paged) { list.Add(item); } } if (markTreeFullLoaded) { TreeHelper.MarkTreeFullLoaded(list); } }
/// <summary> /// 执行 Sql 并读取 DataReader 中的值到实体。 /// </summary> /// <param name="dba">The dba.</param> /// <param name="args">The arguments.</param> /// <param name="readType">Type of the read.</param> /// <param name="sql">The SQL.</param> protected void QueryDataReader(IDbAccesser dba, IEntitySelectArgs args, ReadDataType readType, FormattedSql sql) { //查询数据库 using (var reader = dba.QueryDataReader(sql, sql.Parameters)) { //填充到列表中。 this.FillDataIntoList( reader, readType, args.List, args.FetchingFirst, args.PagingInfo, args.MarkTreeFullLoaded ); } }
/// <summary> /// 在内存中对 IDataReader 进行读取。 /// 注意!!! /// 此方法中会释放 Reader。外层不能再用 Using。 /// </summary> /// <param name="reader">表格类数据。</param> /// <param name="readType">是否索引还是名称去读取 IDataReader。</param> /// <param name="list">需要把读取的实体,加入到这个列表中。</param> /// <param name="fetchingFirst">是否只读取一条数据即返回。</param> /// <param name="pagingInfo">如果不是只取一行数据,则这个参数表示列表内存分页的信息。</param> /// <param name="markTreeFullLoaded">如果某次查询结果是一棵完整的子树,那么必须设置此参数为 true ,才可以把整个树标记为完整加载。</param> protected void FillDataIntoList( IDataReader reader, ReadDataType readType, IList<Entity> list, bool fetchingFirst, PagingInfo pagingInfo, bool markTreeFullLoaded ) { if (_repository.SupportTree) { this.FillTreeIntoList(reader, readType, list, markTreeFullLoaded, pagingInfo); return; } //如果正在分页,而且支持数据库层面的分页,则不使用内存分页。 if (!PagingInfo.IsNullOrEmpty(pagingInfo) && this.GetPagingLocation(pagingInfo) == PagingLocation.Database) { pagingInfo = null; } var readByIndex = readType == ReadDataType.ByIndex; Action<IDataReader> rowReader = dr => { var entity = readByIndex ? this.CreateByIndex(dr) : this.CreateByName(dr); list.Add(entity); }; if (fetchingFirst) { if (reader.Read()) { rowReader(reader); } } else { PagingHelper.MemoryPaging(reader, rowReader, pagingInfo); } }
public List<System.Guid> GetInformationenTypenFromDataTemplate(ReadDataType DataType) { List<System.Guid> InformationenTypen = new List<Guid>(); String DataTemplateName = String.Empty; switch (DataType) { case ReadDataType.All: InformationenTypen.AddRange(GetInformationenTypen("")); break; case ReadDataType.Berichte: InformationenTypen.AddRange(GetInformationenTypen("Informationen")); break; case ReadDataType.Events: InformationenTypen.AddRange(GetInformationenTypen("Ereignisse")); InformationenTypen.AddRange(GetInformationenTypen("AVEvent")); break; } return InformationenTypen; }
private DataCollection<CommonSearchClass> ReadSearchDataAdvanced(ReadDataType DataType, ReadDataTimingType DataTimingType, DateTime? TimeA, DateTime? TimeB, DateTime? ModFrom, DateTime? ModTo, String SpecificWhereAddOn, int MaxNumberOfEntries = -1) { List<System.Guid> InformationenTypen = DataModell.GetInformationenTypenFromDataTemplate(DataType); DataCollection<CommonSearchClass> Result = new DataCollection<CommonSearchClass>(); switch (DataType) { case ReadDataType.All: foreach (DataRow CommonSearchClassEntry in LoadCommonSearchClassEntries(TimeA, TimeB, ModFrom, ModTo, SpecificWhereAddOn, MaxNumberOfEntries)) { Result.Add(new CommonSearchClass(CommonSearchClassEntry)); } break; case ReadDataType.Berichte: case ReadDataType.Events: foreach (DataRow CommonSearchClassEntry in LoadCommonSearchClassEntries(TimeA, TimeB, ModFrom, ModTo, SpecificWhereAddOn, MaxNumberOfEntries)) { if (CommonSearchClassEntry["TypID"] == Convert.DBNull) continue; System.Guid TypID = (System.Guid) CommonSearchClassEntry["TypID"]; if (InformationenTypen.Contains((System.Guid) CommonSearchClassEntry["TypID"])) Result.Add(new CommonSearchClass(CommonSearchClassEntry)); } break; } return Result; }