FIlter Large Collections

Chris C's Avatar

Chris C

05 May, 2010 06:32 PM via web

Hello,

I've setup a couple classes (Client, Invoice) that have a one-to-many relationship between them. I can write the following:

Client client = GetClient();
foreach (Invoice invoice in client.Invoices)
{
     // Check if the invoice has been paid, if not then do stuff to get it paid.
}

But what I really want to do is have the line:

client.Invoices

only return the unpaid invoices. If I could write something like on of the below:

client.Invoices.Filter("Some Filter")
client.UnpaidInvoices()

I know I could write a customer query using CreateCriteria or use the Session.CreateFilter but I was wondering if there was an better way.

Thank you.

  1. Support Staff 2 Posted by James Gregory on 16 May, 2010 05:24 PM

    James Gregory's Avatar

    Your best bet is to use the criteria for queries such as this, that's what it's designed for.

  2. James Gregory closed this discussion on 16 May, 2010 05:24 PM.

  3. Paul Batum re-opened this discussion on 17 May, 2010 05:01 AM

  4. Support Staff 3 Posted by Paul Batum on 17 May, 2010 05:01 AM

    Paul Batum's Avatar

    You could also use 'where' to filter the invoices. You provide a SQL predicate to be included in the where statement. Something like:

    HasMany(x => x.UnpaidInvoices)
      .Where("InvoicePaid = 0")
    

    I forget the syntax exactly but you should be able to find some examples on google.

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    What is five times five?