在本例中,c#datatable左联接
本文关键字:c#datatable | 更新日期: 2023-09-27 18:29:41
我有这个代码
var result = (from row1 in table.AsEnumerable()
join row2 in tabelPopup.AsEnumerable()
on row1.Field<string>("CallID") equals
row2.Field<string>("callID")
where row1.Field<string>("Direction") == "I"
select new
{
Agent = row1.Field<string>("Agent"),
StartTime = row1.Field<string>("StartTime"),
Reason = row2.Field<string>("Reason")
});
其中table
和tablePopup
是数据表,
正如你所看到的,我正在加入。我想左接,你能帮我吗?
我读了很多书,发现我必须做join
和into
,然后用.DefaultOfEmpty()
函数做into name
,但我不能
var left_outer_join =
from row1 in table.AsEnumerable()
join row2 in tabelPopup.AsEnumerable()
on row1.Field<string>("CallID") equals row2.Field<string>("callID")
into outJoin
where row1.Field<string>("Direction") == "I"
from oj in outJoin.DefaultIfEmpty()
select new {
Agent = row1.Field<string>("Agent"),
StartTime = row1.Field<string>("StartTime"),
Reason = (oj == null)
? String.Empty
: oj.Field<string>("Reason")
};