var dt = new DataTable();
var list = dt.AsEnumerable();
var qurey = from tmp in list
where 1 == 1
select new ent()
{
Id = tmp.Field<string>("Id"),
Name = tmp.Field<string>("Name")
};
qurey.ToList();
public class ent
{
public string Id { get; set; }
public string Name { get; set; }
}
//优化
var dt = new DataTable();
dt.Columns.Add("Id");
dt.Columns.Add("Name");
dt.Columns.Add("Addre");
DataRow dr = dt.NewRow();
dr["Id"] = "01";
dr["Name"] = "King";
dr["Addre"] = "addreeeeeee";
dt.Rows.Add(dr);
var list = dt.AsEnumerable();
var qurey = list.Select(tmp => new
{
Id = tmp.Field<string>("Id"),
Name = tmp.Field<string>("Name")
});
var lis = qurey.ToList();
var dtTmp = ToDataTable(lis);