Best method to use IDataReader as IEnumerable?

后端 未结 6 844
攒了一身酷
攒了一身酷 2021-02-06 13:16

I need to use Linq on any IDataReader implementations like this

var c = sqlDataReader.AsEnumerable().Count();

Example:

<
6条回答
  •  后悔当初
    2021-02-06 13:54

    You can use this:

    MyDataReader.Cast()
    

    But don't forget to have the linq statement execute before you close the DataReader.
    using ToList() for instance

提交回复
热议问题