Skip to content

Instantly share code, notes, and snippets.

@goyuix
Last active August 29, 2015 14:28
Show Gist options
  • Save goyuix/07d18b5706155b84e2a7 to your computer and use it in GitHub Desktop.
Save goyuix/07d18b5706155b84e2a7 to your computer and use it in GitHub Desktop.
// remember to force exactly one evaluation of the IEnumerable through Map
public static class FluentDataReader
{
public delegate object MapDelegate<T>(IDataReader reader);
public static IEnumerable<T> Map<T> (this IDataReader reader, MapDelegate<T> mapper) where T : class
{
while (reader.Read())
{
yield return mapper(reader) as T;
}
reader.Dispose(); // this will help catch errors with trying to reuse this DataReader
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment