CREATE TABLE [dbo].[OrderHistory](
[RecordID] [int] IDENTITY(1,1) NOT NULL,
[UserID] [int] NOT NULL, /* FK to user table*/
[ItemID] [int] NOT NULL, /* FK to Item table */
[PurchaseDate] [datetime] NOT NULL,
[UnitPrice] [money] NOT NULL,
[Quantity] [float] NOT NULL,
PRIMARY KEY CLUSTERED
(
[RecordID] ASC
) ON [PRIMARY]
我有一个表来保存用户的订单历史记录。我需要计算用户每年花费的总金额。如果我直接写SQL查询,这是非常简单明了:Nhibernate sum/groupby question
select SUM(UnitPrice * Quantity) as TotalAmount, DATEPART(yyyy, PurchaseDate)
from OrderHistory
where UserId = 1
group by DATEPART(yyyy, PurchaseDate)
计划的对象模型是:
public class YearlySummary {
public virtual int Year {
get;
set;
}
public virtual decimal TotalSpent {
get;
set;
}
}
但我怎么能做到这一点NHibernate的?
感谢 哈迪
NHibernate查询在对象模型上工作,而不在数据库模型上工作。你的对象模型是什么? – 2011-02-26 21:04:45