Click here to Skip to main content
11,580,000 members (73,006 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: LINQ C#4.0 .NET4
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.

 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 26-Feb-13 1:57am
Comments
LokoLuke at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

 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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 208
1 Frankie-C 170
2 Abhinav S 65
3 Sergey Alexandrovich Kryukov 65
4 Dave Kreskowiak 43
0 OriginalGriff 1,088
1 Sergey Alexandrovich Kryukov 750
2 Abhinav S 638
3 Suvendu Shekhar Giri 433
4 F-ES Sitecore 420


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 27 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100