-
Notifications
You must be signed in to change notification settings - Fork 6
LINQ Provider
Nemo implements IQueryable<> with limited support LINQ support: where
, order by
as well as Skip and Take extension methods (for pagination). The implementation is considered experimental and is under current development.
The purpose of the NemoQueryable<>
was to introduce IQueryable<>
equivalent for ObjectFactory.Select<>
method.
Note: grouping, joins, aggregate functions, custom projections as well as ordering by anything other than column name are not currently supported.
var query = from c in new NemoQueryable<Customer>()
where c.Country == "USA"
order by c.CustomerID descending
select c;
var customers = query.Skip(20).Take(10);
// Executes the query here
foreach(var customer in customers)
{
// Do something here
}
Underneath NemoQueryable<>
uses ObjectFactory.Select
method to generate required SQL. A developer may choose to invoke Select
method directly.
var customers = ObjectFactory
.Select<Customer>(c => c.Country == "USA", page: 3, pageSize: 10);
After making a call to Select
one can chain Include
methods in order to eagerly load navigational properties.
var customers_with_orders_1 = ObjectFactory
.Select<Customer>(c => c.Country == "USA", page: 3, pageSize: 10)
.Include<Customer, Order, OrderDetail>((c, o) => c.Id == o.CustomerId, (o, d) => o.Id == d.OrderId);
The above-mentioned result can be obtained using two includes instead of one:
var customers_with_orders_2 = ObjectFactory
.Select<Customer>(c => c.Country == "USA", page: 3, pageSize: 10)
.Include<Customer, Order>((c, o) => c.Id == o.CustomerId)
.Include<Order, OrderDetail>((o, d) => o.Id == d.OrderId);