views:

1475

answers:

1

I have the following domain object:

public class Data
{
    public virtual int ID { get; set; }
    public virtual DateTime TimeStamp { get; set; }
    public virtual int Value { get; set; }

    public virtual Channel Channel { get; set; }       

}

I'm using Repositories from Rhino.Commons. I need to select sum of values for few channels for some period. These values should be ordered by channel ID. I use the following query (in repository method):

var criteria = DetachedCriteria.For<LiveData>()
            .Add(Restrictions.Le("TimeStamp", startDate))
            .Add(Restrictions.Ge("TimeStamp", endDate))
            .Add(Restrictions.InG<Channel>("Channel", channels))
            .SetProjection(Projections.Sum("Value"))
            .SetProjection(Projections.GroupProperty("Channel"));

long[] result = ReportAll<long>(criteria, Projections.ProjectionList(), Order.Asc("Channel"));

And I receive error at the last line because this query returns not a list of long numbers. It returns a list of objects like this (it works with it):

public class ResultValue
{
    public virtual Channel Channel { get; set;}
    public virtual int Value { get; set; }
    public ResultValue()
    {            
    }

    public ResultValue(int value, Channel channel)
    {
        this.Value = value;
        this.Channel = channel;
    }
}

This is because I've added Projections.GroupProperty("Channel") projection to criteria to do a grouping. Is there any way to remove one of projections (Projections.GroupProperty("Channel") from my sample) from resultset or to add a grouping without projection?

+1  A: 

This is a pending NHibernate issue.

Mauricio Scheffer