Skip to content

LINQ Provider

Max Stepanskiy edited this page Mar 31, 2021 · 15 revisions

Nemo implements IQueryable<> with limited support LINQ support: where, order by as well as Skip, Take, First and FirstOrDefault extension methods.

The purpose of the NemoQueryable<> (or NemoQueryableAsync<>) was to introduce IQueryable<> equivalent for ObjectFactory.Select<> (or ObjectFactory.SelectAsync<>) method.

Note: grouping, joins, 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
} 

Select Method

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);

Include Methods

After making a call to Select one can chain Include methods in order to eagerly load navigational properties.

var customers_with_orders = 
    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);
Clone this wiki locally