Click here to Skip to main content
11,924,573 members (61,719 online)
Rate this:
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 2:57am
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

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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151125.3 | 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