Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IEnumerable traversed twice #422

Closed
MadsSvejstrup opened this issue Aug 25, 2022 · 0 comments
Closed

IEnumerable traversed twice #422

MadsSvejstrup opened this issue Aug 25, 2022 · 0 comments

Comments

@MadsSvejstrup
Copy link

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.

@Discolai Discolai mentioned this issue Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants