c# - IQueryable different results when adding where clause later -


i'm experiencing variations in results depending on when i'm specifying clause...

if use:

query1 = ct in customertransfers          join j in jobs on ct.stock.jobno equals j.jobno          join o in organisations on j.organisationid equals o.organisationid ogroup          o in ogroup.defaultifempty()          ct.organisationid == intcustomerb &&                   ct.neworganisationid == intcustomera          group new { ct, j, o } ct.wedno g          let largestvalue = g.orderbydescending(x => x.ct.transferno).firstordefault()          select new          {              id = g.key,              organisationid = largestvalue.ct.organisationid,              neworganisationid = largestvalue.ct.neworganisationid,          };  query1.tolist(); 

it gives 2 results... if remove following initial iqueryable construction:

where ct.organisationid == intcustomerb && ct.neworganisationid == intcustomera 

and add them in later using clause so:

query2 = ct in customertransfers          join j in jobs on ct.stock.jobno equals j.jobno          join o in organisations on j.organisationid equals o.organisationid ogroup          o in ogroup.defaultifempty()          group new { ct, j, o } ct.wedno g          let largestvalue = g.orderbydescending(x => x.ct.transferno).firstordefault()          select new          {              id = g.key,              organisationid = largestvalue.ct.organisationid,              neworganisationid = largestvalue.ct.neworganisationid,          };  query2 = query2.where (q => q.organisationid == intcustomerb && q.neworganisationid == intcustomera);  query2.tolist(); 

i 1 result.

so correct in assuming using query2 method wrapping whole iqueryable clause opposed adding clause iqueryable (which result in iqueryable identical query1)? seems logical explanation.

prior 'revelation' have thought achieve 1 result (query2) have had evaluate query2 .tolist() , apply statement list.

yes, yes are.

or in longer form: second example creates iqueryable further operated on method, you've got first iqueryable being filtered instead of filtering happening within first query. it's not clear why returns different results, in second example grouping happens before filtering, significant.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -