Best method to use IDataReader as IEnumerable?

后端 未结 6 853
攒了一身酷
攒了一身酷 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:42

    You can just load the DataReader into a DataTable and then Select():

    DataTable dt = new DataTable();
    dt.Load(dataReader);
    DataRow[] rows = dt.Select();        //DataRow[] Implements IEnumerable
    

    or

    IEnumerable rows = dt.AsEnumerable();
    

提交回复
热议问题