开发者

How can I filter collections using NHibernate Criteria?

开发者 https://www.devze.com 2023-03-02 20:13 出处:网络
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?

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 positiv开发者_如何学Ce 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?


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消