Click here to Skip to main content
12,295,791 members (51,436 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# .NET 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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 27 Feb 2013
Copyright © CodeProject, 1999-2016
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