简体   繁体   中英

How can i Convert My SQL Query To Linq w/ not equals?

This is my sql query;

select * from kirala inner join saatler on Kirala.Tarih = '2020-05-31' and Kirala.Onay = 'true' and Kirala.SaatID != saatler.ID

i was convert this;

var kirala2 = from t1 in _context.Kirala
                          join t2 in _context.Saatler on t1.SaatID equals t2.ID 
                          where t1.Tarih == "2020-05-31" && t1.Onay == true && t1.YatID == id
                          select new Saatler { Saat = t2.Saat, ID = t2.ID };

But this is not working for me because t1.SaatID equals t2.ID i cant use not equals what else can I do?

You can just move all the conditions in the join to a where

var kirala2 = from t1 in _context.Kirala
              from t2 in _context.Saatler 
              where t1.SaatID != t2.ID 
                    && t1.Tarih == "2020-05-31" 
                    && t1.Onay == true 
                    && t1.YatID == id
              select new Saatler { Saat = t2.Saat, ID = t2.ID };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM