我有以下域对象:
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") from my sample)或添加没有投影的分组?