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

前端 未结 7 1051
既然无缘
既然无缘 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:14

    I think that's because your creating a anonymous type to hold the Field object. Try this:

        var query = from SPhysician in dtPhysicianServer.AsEnumerable()
                    join CPhysician in dtPhysicianClient.AsEnumerable()
                    on SPhysician.Field("PhysicianNumber") equals
                        CPhysician.Field("PhysicianNumber")
                    select CPhysician;
    
        DataTable FilterDt = query.CopyToDataTable();
    

    Definition of CopyToDataTable:

    public static DataTable CopyToDataTable(
        this IEnumerable source
    )
    where T : DataRow
    

    So what you select with the query must be of type IEnumerable where T extends DataRow

提交回复
热议问题