Last active
August 29, 2015 14:28
-
-
Save goyuix/07d18b5706155b84e2a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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