DataTable does not contain definition for AsEnumerable

前端 未结 6 1908
轮回少年
轮回少年 2020-11-30 06:12

Using linq to query a datatable returns the following error: CS0117: \'DataSet1.map DataTable\' does not contain a definition for \'AsEnumerable\'

Project include

6条回答
  •  难免孤独
    2020-11-30 06:56

    Google search "system.data.datatable does not contain a definition for asenumerable" brought me here, and my trouble was missing:

    using System.Data;
    

    Due to my implement the error message was a bit misleading. Hence, my answer to this question. Code was like...

    public List MyMethod(params) {
       return new mynamespace.myclasslib.myclass().GetDataTable(params).AsEnumerable()
          .etc
    }
    

    Once I tried to explicitly declare the DataTable, it became obvious that I was missing the using statement.

提交回复
热议问题