Click here to Skip to main content
11,806,590 members (68,166 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# .NET LINQ C#4.0 .NET4

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( < DateTime.Now.AddMonths(4) && ERPConnect.ConversionUtils.SAPDate2NetDate( >= 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)

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
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
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)

So Where().Sum() moved into query select part.

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

  Print Answers RSS
0 ppolymorphe 205
1 OriginalGriff 175
2 Richard Deeming 175
3 Sergey Alexandrovich Kryukov 170
4 Abhinav S 120
0 OriginalGriff 3,380
1 Maciej Los 1,990
2 CPallini 1,915
3 KrunalRohit 1,907
4 ppolymorphe 1,317

Advertise | Privacy | Mobile
Web01 | 2.8.151002.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