2015-02-10 3 views
-2
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

Использовать 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(); 
+0

спасибо, я изменяю это, это тоже работа. из р в EcOrders присоединиться к t1 в иерархиях на p.Consgipos равна t1.Storeid в t1tmp из T1T в t1tmp.DefaultIfEmpty() присоединиться к t2 в иерархиях на p.Ordpos равна t2.Storeid в t2tmp от t25 в t2tmp .DefaultIfEmpty() выбрать новый { p.Shopid, \t p.Consgipos, \t CStoreName = t1t.Storename, \t p.Ordpos, \t OStoreName = t25.Storename \t } –

Смежные вопросы