组合没有JOIN关键字的表
var res2 = from u in dtEmp.AsEnumerable()
from v in dtDept.AsEnumerable()
where u.Field<int>("DepartmentID") == v.Field<int>("DepartmentID") &&
u.Field<double>("Salary") > 10000
select new
{
Name = u.Field<string>("Name"),
Department = v.Field<string>("DepartmentName")
};
如何使用Lambda Expression而不使用Join Keyword?
答案 0 :(得分:0)
您是否想要从SQL语法切换到Method Chain语法?即:
var res2 = dtEmp.AsEnumerable()
.SelectMany(u => dtDept.AsEnumerable(), (u, v) => new {u, v})
.Where(@t => u.Field<int>("DepartmentID") == v.Field<int>("DepartmentID") &&
u.Field<double>("Salary") > 10000).Select(@t => new
{
Name = u.Field<string>("Name"),
Department = v.Field<string>("DepartmentName")
});