none
question on where RRS feed

  • Question

  • Hi how do i ignore the "where" statement if the data from t is null or empty

     public IList<Payment> GetPaymentForCloseCash()
        {
          IList<Payment> output = new List<Payment>();
          using (JamminDataContext db = new JamminDataContext())
          {
            var result = from p in db.Payments
                   let t = (from m in db.PaymentCloseChecklists
                       select m).OrderByDescending(x => x.Id).First()
                   where p.DateIssue > t.DateClosed
                   select p;
            return result.ToList();
          }
        }
    

    Tuesday, January 25, 2011 7:18 AM

Answers

  • hi thanks for your replace. i used this way instead . This works out the same

            var re = (from m in db.PaymentCloseChecklists
                 select m).OrderByDescending(x => x.Id).First();
    
            var result = from p in db.Payments
                   select p;
    
            if(re != null)
            {
              result = result.Where(x => x.DateIssue > re.DateClosed);
            }     
            return result.ToList();
    

    • Marked as answer by belinq Thursday, January 27, 2011 3:01 AM
    Wednesday, January 26, 2011 9:40 AM

All replies

  • public IList<Payment> GetPaymentForCloseCash()
        {
          IList<Payment> output = new List<Payment>();
          using (JamminDataContext db = new JamminDataContext())
          {
            var result = from p in db.Payments
                   let t = (from m in db.PaymentCloseChecklists
                       select m).OrderByDescending(x => x.Id).First()
                   where t != null && t.DateClosed != null p.DateIssue > t.DateClosed
                   select p;
            return result.ToList();
          }
        }

     

    Try the above code.


    Pratap --Mark the best replies as answers!
    Tuesday, January 25, 2011 1:41 PM
  • Hi Pratap, i tried your code but it gives error on syntax problem. Should there be a ( ) on the if statement after where? 
    Wednesday, January 26, 2011 12:34 AM
  • Hi Pratap, i tried your code but it gives error on syntax problem. Should there be a ( ) on the if statement after where? 


    Brackets aren't necessary unless in this case.

    If you look carefully, there's a conditional operator missing in the where after t.DateClosed != null.

    Wednesday, January 26, 2011 9:15 AM
  • hi thanks for your replace. i used this way instead . This works out the same

            var re = (from m in db.PaymentCloseChecklists
                 select m).OrderByDescending(x => x.Id).First();
    
            var result = from p in db.Payments
                   select p;
    
            if(re != null)
            {
              result = result.Where(x => x.DateIssue > re.DateClosed);
            }     
            return result.ToList();
    

    • Marked as answer by belinq Thursday, January 27, 2011 3:01 AM
    Wednesday, January 26, 2011 9:40 AM