Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Please help me convert SQL to LINQ

Tags:

c#

sql

linq

I have this query that i've been trying to figure out how to convert to 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)

And here is my LINQ so far:

(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 }
);

I am getting an error message on the first join stating"The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'."

All searches I did, related to type match errors, but I quadruple checked all my types within the joins, and they are the same.

like image 680
Sean Haddy Avatar asked Jan 13 '12 22:01

Sean Haddy


1 Answers

Try to do something like this :

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

Should work.

like image 143
Tigran Avatar answered Oct 06 '22 18:10

Tigran