Is there an implementation of IQueryable over DbDataReader?

后端 未结 1 1493
孤街浪徒
孤街浪徒 2021-01-14 02:19

I have a lot of existing code which uses raw ADO.NET (DbConnection, DbDataReader, etc). I would like to transition to using LINQ to SQL for new code, but for now put both t

相关标签:
1条回答
  • 2021-01-14 02:40

    I can't see any benefit in implement IQueryable<T> - that suggests more functionality than is actually available - however, you could implement it as an IEnumerable<T> easily enough, with the caveat that it is once-only. An iterator block would be a reasonable choice:

        public static IEnumerable<IDataRecord> AsEnumerable(
            this IDataReader reader)
        {
            while (reader.Read())
            {
                yield return reader; // a bit dangerous
            }
        }
    

    The "a bit dangerous" is because the caller could cast it back and abuse it...

    0 讨论(0)
提交回复
热议问题