如何使用 NHibernate Criteria 过滤集合?

发布于 2024-11-04 13:29:10 字数 788 浏览 0 评论 0原文

据我所知,您可以在 NHibernate 中使用过滤器来仅加载子集合的部分内容。我希望能够使用 Criteria API 而不是 HQL 来完成此操作。这可能吗?

我的申请中的一些细节: 我正在尝试加载给定日期之后发生的给定供应商的发票,并且具有正行项目。

这些实体看起来像这样:

public partial class Vendor
{
   public virtual string Name {get; set;}
   //A bunch of other properties 
   public virtual ICollection<Invoice> Invoices {get; protected set;}
}

public partial class Invoice
{
   public virtual DateTime? Date {get; set;}
   public virtual ICollection<LineItem> LineItems {get; protected set;}
}

public partial class LineItem
{
   public virtual decimal Amount {get; set;}
}

最初,我只是拉动行项目,但现在他们希望用户能够输入一堆标准来选择供应商。我已经有了允许用户使用 Criteria API 指定供应商的 UI/代码,因此我想应用一个过滤器来仅提取对给定日期之后发生的发票有利的 LineItems。使用 Criteria API 可以实现这一点吗?如果没有,我至少可以不将过滤器定义添加到我的映射文件中吗?

I understand that you can use filters in NHibernate to only load parts of child collections. I would like to be able to do this using the Criteria API, instead of HQL. Is this possible?

Some specifics from my application:
I'm trying to load the invoices for a given vendor that occur after a given date, and have positive line items.

The entities look something like this:

public partial class Vendor
{
   public virtual string Name {get; set;}
   //A bunch of other properties 
   public virtual ICollection<Invoice> Invoices {get; protected set;}
}

public partial class Invoice
{
   public virtual DateTime? Date {get; set;}
   public virtual ICollection<LineItem> LineItems {get; protected set;}
}

public partial class LineItem
{
   public virtual decimal Amount {get; set;}
}

Originally, I was just pulling line items, but now they want the user to be able to input a bunch of criteria to select the vendor. I already have the UI/code to allow the user to specify vendors using the Criteria API, so I'd like to apply a filter to only pull the LineItems that are positive for Invoices that occur after a given date. Is this possible using the Criteria API? If not, can I at least get away without adding the filter-defs to my mapping file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

找回味觉 2024-11-11 13:29:10

更新了答案,第一次没有读好......我不知道这是否有帮助,但我遇到了同样的问题,我只想从子集合中提取活动。这使用了 queryover,但它是标准之上的包装器,因此可以完成......
这里是...

Updated the answer, didn't read it well the first time... I don't know if this will help but I ran into the same issue where I only wanted actives being pulled of a child collection. This uses queryover but it's a wrapper on top of criteria so it can be done...
Here it is...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文