SELECT t0.SHOPID,
t0.CONSGIPOS,
t1.StoreName as CStorename,
t0.ORDPOS,
t2.StoreName as OStoreName
FROM EC_ORDER t0
LEFT JOIN HIERARCHY t1
ON (t0.CONSGIPOS = t1.STOREID)
LEFT OUTER JOIN HIERARCHY t2
ON (t2.STOREID = t0.ORDPOS)
答案 0 :(得分:0)
在DefaultIfEmpty
中使用LINQ
左连接。试试这个:
var result = (from t0 in context.EC_ORDER
join t1 in context.HIERARCHY on t0.CONSGIPOS == t1.STOREID into t1tmp
from t1t in t1tmp.DefaultIfEmpty()
join t2 in context.HIERARCHY on t0.ORDPOS == t2.STOREID into t2tmp
from t2t in t2tmp.DefaultIfEmpty()
select {
t0.SHOPID,
t0.CONSGIPOS,
CStorename = t1t != null ? t1t.StoreName : null,
t0.ORDPOS,
OStoreName = t2t != null ? t2t.StoreName : null
}).ToList();