var a = AttendanceItemList.GroupJoin( AttendanceFormulaList, (i) => i.AttendanceCode, (f) => f.ItemCode, (i, f) => new { i = i, f = f }); foreach (var attenitem in a) {}
我的 目的是 得到 :AttendanceItemList i left join AttendanceFormulaList f on i.AttendanceCode=f.ItemCode 做连接后的结果及 请问我foreach里的代码应该 怎么写呢
或 我整个 这段 代码 该 怎么写呢
你这里的写法为:
var result = from a in AttendanceItemList join b in AttendanceFormulaList on a.AttendanceCode equals b.ItemCode into t from c in t.DefaultIfEmpty() select new { a.AttendanceCode, b.ItemCode, //... other colnums } ;
这里介绍了 join, left join 等的写法,你去学习一下
http://www.cnblogs.com/Mayvar/archive/2011/07/04/wanghonghua_201107040534.html
后边加上selectMany
你下一个linqpad学一下linq吧
AttendanceItemList.GroupJoin(
AttendanceFormulaList,
(i) => i.AttendanceCode,
(f) => f.ItemCode,
(i, f) => new { i = i, f = f }).SelecteMany(........
可以看一下这个帖子