Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello

I 'd like to modify my current query to include all the materials even if it doesn't satisfy the where condition. This is needed for a later joining.

C#
var qtreqd_ho4 = (from qt0 in ReqdMats
                  where (ERPConnect.ConversionUtils.SAPDate2NetDate(qt0.date) < DateTime.Now.AddMonths(4) && ERPConnect.ConversionUtils.SAPDate2NetDate(qt0.date) >= DateTime.Now.AddMonths(3))
                                group qt0 by new { qt0.ID } into g

                                 select new MatRequirements
                                 {
                                     ID = g.Key.ID,
                                     reqmennyiseg = g.Sum(qt0 => qt0.reqmennyiseg)
                                 }).ToList();


So I'd like to include all materials even with 0 qty. iS it going to be a g.Where().Sum()....
Posted
Comments
LokoLuke 26-Feb-13 10:21am    
Why don't you just take the where clause out if the query is not dependant on it??

1 solution

instead of the above this will do, later I realized...

C#
var qtreqdperho = (from qt in ReqdMats
                                  group qt by new { qt.ID } into g
                                  select new ReqdQTYPerMonth
                                  {
                                      Anyag = g.Key.anyagszam,
                                      Hó1Menny = g.Where(ho1 => ERPConnect.ConversionUtils.SAPDate2NetDate(ho1.datum) < DateTime.Now.AddMonths(1) && ERPConnect.ConversionUtils.SAPDate2NetDate(ho1.datum) >= DateTime.Now).Sum(qt1 => qt1.reqmennyiseg)

                                  }).ToList();


So Where().Sum() moved into query select part.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900