private HierarchicalRowInfo GetNextBestRowInfo(IDataReader reader, List <HierarchicalRowInfo> toRead, CancellationToken token, int index) { Contract.Requires(reader != null); Contract.Requires(toRead != null && Contract.ForAll(toRead, t => t != null)); token.ThrowIfCancellationRequested(); if (index > 0 && !reader.NextResult()) { if (toRead.Any(f => f.ShouldThrowIfNotFound(toRead))) { throw new StoredProcedureResultsException(typeof(T), toRead.Select(f => f.ItemType).ToArray()); } return(HierarchicalRowInfo.Empty); } token.ThrowIfCancellationRequested(); if (resultTypesInOrder != null) { if (index >= resultTypesInOrder.Count) { return(null); } var type = resultTypesInOrder[index]; return(toRead.First(f => f.ItemType == type)); } HierarchicalRowInfo result = null; var colNames = Enumerable.Range(0, reader.FieldCount).Select(i => reader.GetName(i)).ToArray(); var fewestRemaining = Int32.MaxValue; foreach (var hri in toRead) { int i; if (hri.MatchesColumns(colNames, out i)) { if (i < fewestRemaining) { fewestRemaining = i; result = hri; } } } return(result); }
public HierarchicalRowInfo( HierarchicalRowInfo parent = null, Type itemType = null, string parentKeyColumnName = null, string itemKeyColumnName = null, IRowFactory rowFactory = null, bool isOptional = false, bool isArray = false) { this.parent = parent; ItemType = itemType; ParentKeyColumnName = parentKeyColumnName; ItemKeyColumnName = itemKeyColumnName; RowFactory = rowFactory; IsOptional = isOptional; IsArray = isArray; }