1

I want to do a total of fields in database for the current week. For eg, If today is wednesday, I want to do a total of current Monday through Wednesday, if its Thursday then Monday through Thursday.. How will I do this using projection queries in NHibernate? In my below code how will I group the data so it displays sum of current week only. The field in database for date is named MyDate and it is of type datetime.

DateTemplate.Criteria = DetachedCriteria.For(typeof(MyBill));


    DateTemplate.Criteria.SetProjection(
    Projections.ProjectionList()
          .Add(Projections.Sum(Projections.Conditional
                            (Restrictions.Eq("PayType", "ABC"),
                                  Projections.Constant(1), Projections.Constant(0))), "GCashSales")
                .Add(Projections.Sum(Projections.Conditional
                            (Restrictions.Eq("PayType", "DEF"),
                                  Projections.Constant(1), Projections.Constant(0))), "GCreditSales"));
appuser
  • 269
  • 1
  • 3
  • 10

1 Answers1

2

The simplest way to do this probably would be to calculate the start/end date outside of the query and add a Between restriction to your projection list.

.Add(Restrictions.Between("MyDate", startDate, endDate))
csano
  • 13,266
  • 2
  • 28
  • 45
  • But how will I calculate(know) the start and end date for the current week? Can you please help me with that? – appuser Jun 01 '11 at 18:35
  • 2
    Does this SO post help you? http://stackoverflow.com/questions/38039/how-can-i-get-the-datetime-for-the-start-of-the-week – csano Jun 01 '11 at 18:41