MiniExcel
MiniExcel copied to clipboard
IEnumerable traversed twice
In an attempt to use DynamicColumns with IDataReader i converted the reader into an IEnumerable<Dictionary<string, object>> using the following method:
private IEnumerable<Dictionary<string, object>> AsDict(IDataReader dataReader)
{
while (dataReader.Read())
{
yield return Enumerable.Range(0, dataReader.FieldCount)
.ToDictionary(
dataReader.GetName,
i => dataReader[i])
;
}
}
However i discovered that this approach did not work because when passing an IEnumerable to MiniExcel.SaveAs() it is iterated twice. In the second iteration the IEnumerable is empty because is data from has dataReader has already been read.
I would be nice if MiniExcel supported proper deferred execution by only traversing the IEnumerable once.