Investor Services edited this page Dec 5, 2017 · 5 revisions

Including DataAccessObject properties

By default, accessing a property that is also a DataAccessObject will cause an additional SELECT query to the database. If you want to automatically include certain properties, Shoalinq will automatically perform the current joins. You can include chains of properties to any depth you like. Including a property at depth N will implicitly include properties at depth 0 - N.


var person = model.People.Include(c => c.BestFriend).First();

// Will not cause an additional query
var person = model.People.Include(c => c.BestFriend.BorrowedBook).ToList();

// Will not cause an additional query

Including RelatedDataAccessObjects properties

It's possible to include a RelatedDataAccessObjects<T> property also using the Include method. Because the property remains a RelatedDataAccessObjects<T> property that implements IQueryable<T>, accessing the property after a query will still perform an additional query. To access the pre-loaded list of related objects use the Items() method on the RelatedDataAccessObjects<T> class.

var book = model.Books.Include(c => c.Borrowers).First();

// Will cause an additional query

// Will not cause an additional query

Deep Includes

You can perform deep/nested includes of items within a collection by using the IncludedItems() extension method.

var book = model
    .Include(c => c.Borrowers.IncludedItems().BestFriend)
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.