请帮我转换SQL到LINQ

时间:2012-01-13 22:46:45

标签: c# sql linq

我有这个查询,我一直在试图找出如何转换为LINQ:

select bjbecd, bjbesk, areotx 
from insku 
inner join iniwre on bjcomp=a7comp and bjbecd=a7becd and bjbesk=a7besk 
inner join initem on bjcomp=arcomp and bjbecd=arbecd 
where a7comp=1 and 
a7wcde in (1,10) and 
a7ohdq>0 and rtrim(a7becd) + rtrim(a7besk) not in
(select skucode from eoditems)

到目前为止,这是我的LINQ:

(from i in db.INSKUs
    join w in db.INIWREs on 
        new { i.BJCOMP, i.BJBECD, i.BJBESK }
        equals  
        new { w.A7COMP, w.A7BECD, w.A7BESK } 
    join t in db.INITEMs on 
        new { i.BJCOMP, i.BJBECD }
        equals 
        new { t.ARCOMP, t.ARBECD }
    where w.A7COMP == 1
    where w.A7WCDE == 1 || w.A7WCDE == 10
    where w.A7OHDQ > 0
    where !(from z in db.EODItems
            select z.SkuCode).Contains(w.A7BECD.TrimEnd() + w.A7BESK.TrimEnd())
    select new { i.BJBECD, i.BJBESK, t.AREOTX }
);

我在第一次连接时收到一条错误消息,指出“join子句中某个表达式的类型不正确。在'Join'调用中类型推断失败。”

我所做的所有搜索都与类型匹配错误有关,但是我在联接中检查了所有类型的四倍,它们是相同的。

1 个答案:

答案 0 :(得分:5)

尝试做这样的事情:

join w in db.INIWREs on 
 new { i.BJCOMP, i.BJBECD, i.BJBESK }
    equals  
       new { BJCOMP = w.A7COMP, BJBECD = w.A7BECD, BJBESK  = w.A7BESK } 

应该工作。