NHibernate Criteria 查询以选择每种类型的最新项目
我需要使用 NHibernate 标准查询查找工作人员提交的最新报告。我确信我需要使用投影,但我不知道如何设置它。
我的域模型的解释:
public class Employee
{
public int Id {get; set;}
public string Name {get; set;}
}
public class Report
{
public int Id {get; set;}
public DateTime? Submitted {get; set;}
public Employee Employee {get; set;}
// Other report properties omitted
}
如果有 5 名员工,每人都有 7 份报告,则查询应返回 5 份报告,每个员工一份,并且 Submitted 属性不为空,并且是最近的一份报告员工。。
I need to find the most recent report submitted by members of staff, using an NHibernate criteria query. I'm sure that I need to use projections, but I can't work out how to set it up.
A paraphrase of my domain model:
public class Employee
{
public int Id {get; set;}
public string Name {get; set;}
}
public class Report
{
public int Id {get; set;}
public DateTime? Submitted {get; set;}
public Employee Employee {get; set;}
// Other report properties omitted
}
If there were 5 members of staff, who each have 7 reports, the query should return 5 reports, one per employee, with the Submitted property being not null, and being most recent one for that employee.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对此不太确定,但请检查一下:
I am not quite sure about this, but check it out: