Last active
April 10, 2020 19:29
-
-
Save Larry57/3910167 to your computer and use it in GitHub Desktop.
Linq enumerate a DataReader
This file contains 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
/* How to use with a DataReader: */ | |
public void Test() | |
{ | |
var Res = | |
from Dr in MyDataReader.Enumerate() | |
select new { | |
ID = (Guid)Dr["ID"], | |
Description = Dr["Desc"] as string | |
}; | |
} | |
*/ | |
public static IEnumerable<T> Enumerate<T>(this T reader) where T: IDataReader | |
{ | |
using(reader) | |
while(reader.Read()) | |
yield return reader; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment