1

I have two simple entities with one-to-many relationship:

public class Customer
{
    public int Id { get; private set; }
    public IList<Order> Orders { get; private set; }
}

public class Order
{
    public DateTime Date { get; set; }
}

Let's imagine, that there could be a lot of Orders for a particular Customer, and I want to see only last-month-orders.

Can I do this somehow if Orders property is lazy-loaded? I want something like:

var orders = customer.Orders.Where(x => x.Date > DateTime.Now.AddMonths(-1)).ToList();

but now nHibernate requests all the Orders on this line (SELECT * FROM Orders WHERE customerId='{0}'), and linq-restrictions are applied on the loaded data, but I want it to be applied to SQL (SELECT * FROM Orders WHERE customerId='{0}' AND date > '2011-07-31').

Is this achievable with nHibernate? Can Entity Framework do this?

2 Answers 2

1

Is this achievable with nHibernate? Can Entity Framework do this?

Unfortunately no. NHibernate and EF cannot handle this situation.

Sign up to request clarification or add additional context in comments.

Comments

1

Try NHibernate 3, linq support there is much better than in 2nd version. Otherwise you can make request using criterions syntax.

1 Comment

I do use 3rd version. I can use criterions when doing request over the Session, but the question is about doing this with lazy-loaded collections.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.