I need to use Linq on any IDataReader implementations like this
var c = sqlDataReader.AsEnumerable().Count();
Example:
<
Try, this:
public static class DataReaderExtension
{
public class EnumeratorWrapper
{
private readonly Func moveNext;
private readonly Func current;
public EnumeratorWrapper(Func moveNext, Func current)
{
this.moveNext = moveNext;
this.current = current;
}
public EnumeratorWrapper GetEnumerator()
{
return this;
}
public bool MoveNext()
{
return moveNext();
}
public T Current
{
get { return current(); }
}
}
private static IEnumerable BuildEnumerable(
Func moveNext, Func current)
{
var po = new EnumeratorWrapper(moveNext, current);
foreach (var s in po)
yield return s;
}
public static IEnumerable AsEnumerable(this T source) where T : IDataReader
{
return BuildEnumerable(source.Read, () => source);
}
}