Why am I not getting .CopyToDataTable() in Linq Query()

前端 未结 7 1053
既然无缘
既然无缘 2020-12-11 02:22

This following code example is borrowed from MSDN here. I am not getting query.CopyToDataTable() available in my code. (see the commented line in my following code).

7条回答
  •  执笔经年
    2020-12-11 03:23

    Your select statement is returning a sequence of strings (IEnumerable or IQueryable), not a sequence of DataRows. CopyToDataTable() is only available on IEnumerable where T is or derives from DataRow.

    Instead of select new { ... } - which will just get you a new sequence of that type, try:

    select CPhysician;
    

    Which should return the desired sequence of CPhysician rows.

    Edit If you wish to convert a non-datatable-derived T to a datatable, MSDN has a sample class that reflects out any type and performs the conversion.

    http://msdn.microsoft.com/en-us/library/bb669096.aspx

提交回复
热议问题