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?