我有以下域对象:
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; }
}
我正在使用Rhino.Commons的存储库。我需要在一段时间内为少数通道选择值的总和。这些值应按通道ID排序。我使用以下查询(在存储库方法中):
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"));
我在最后一行收到错误,因为此查询不返回长号列表。它返回一个像这样的对象列表(它可以使用它):
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;
}
}
这是因为我已将Projections.GroupProperty(“Channel”)投影添加到标准以进行分组。有没有办法从结果集中删除一个投影(Projections.GroupProperty(“Channel”))或者添加一个没有投影的分组?