简体   繁体   中英

c# linq not equals variation

I have a linq query w/ entity frameworks that works and gets the needed information, but now i am having trouble doing the opposite.

Currently it gets all the data that is needed using the joins to link tables but i need to to get some data that is not match some of the joins.

I know you can only use "equals" om linq, but i need info that is not equals ie join ec in c.IsoNe on ap.idLook not equals ec.idAll

Below is the working code, but not how i need it now. any help would be appreciated...

var test = (from bil in bilats
                join ap in c.Allegro on bil.idAll equals ap.idAll
                join ec in c.IsoNe on ap.idLook equals ec.idAll
                join cb in c.Comp on ap.idCompBuy equals cb.idComp
                join cs in c.Com on ap.idCompSell equals cs.idComp
                join iby in c.IsoNe on cb.idComp equals iby.idComp
                join iss in c.IsoNe on cs.idComp equals isl.idComp
             orderby bil.HBegin ascending
             where bil.HBegin >= ec.DateTStart
             where bil.HBegin < ec.DateTEnd
             select new
             {
                 Cont = ec.ContractID,
                 ContType = ap.idScheduleType,
                 Sel = isel.ISONE1,
                 Buy = ibel.ISONE,
                 HBegin = bil.HBegin,
              }).ToList();

As far as I know, you'll have to create a Cartesian product and then use a where-condition to filter it. (I'm making the perhaps rash assumption that you want an inner join rather than a left join, but an inner join is what the join keyword represents.) Something like this:

var test = (from bil in bilats
                join ap in c.Allegro on bil.idAll equals ap.idAll
                from ec in c.IsoNe where ap.idLook != ec.idAll
                join cb in c.Comp on ap.idCompBuy equals cb.idComp
                join cs in c.Com on ap.idCompSell equals cs.idComp
                join iby in c.IsoNe on cb.idComp equals iby.idComp
                join iss in c.IsoNe on cs.idComp equals isl.idComp
             orderby bil.HBegin ascending
             where bil.HBegin >= ec.DateTStart
             where bil.HBegin < ec.DateTEnd
             select new
             {
                 Cont = ec.ContractID,
                 ContType = ap.idScheduleType,
                 Sel = isel.ISONE1,
                 Buy = ibel.ISONE,
                 HBegin = bil.HBegin,
              }).ToList();

Sounds like a join might be the wrong approach. Have a look at unions or subqueries

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