【问题标题】:NHibernate Criteria API, Projections and resultNHibernate Criteria API、预测和结果
【发布时间】:2010-10-07 17:20:24
【问题描述】:

我有以下域对象:

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)或添加一个没有投影的分组?

【问题讨论】:

    标签: nhibernate criteria rhino


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-11
      • 1970-01-01
      • 2012-02-07
      • 1970-01-01
      • 2011-01-12
      • 2013-03-13
      相关资源
      最近更新 更多