Skip to content

Instantly share code, notes, and snippets.

@Larry57
Last active April 10, 2020 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Larry57/3910167 to your computer and use it in GitHub Desktop.
Save Larry57/3910167 to your computer and use it in GitHub Desktop.
Linq enumerate a DataReader
/* 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