question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Design meeting notes - January 8, 2015

See original GitHub issue

Multi-level Include syntax

Since EF 4.1, multi-level includes have been possible using either string syntax:

customers.Include("Contact.HomeAddress");
customers.Include("Orders.OrderDetails")

or lambda syntax:

customers.Include(c => c.Contact.HomeAddress);
customers.Include(c => c.Orders.Select(o => o.OrderDetails));

Note that for the lambda syntax we make use of the LINQ Select method when adding an additional level of include after a collection navigation property. This is because the collection navigation property is an IEnumerable<> of the entity type rather than the entity type itself.

For example, to include all products and their suppliers, plus all reviews and review authors:

categories
    .Include(c => c.Products.Select(p => p.Reviews.Select(r => r.Author)))
    .Include(c => c.Products.Select(p => p.Supplier));

The Select syntax has two issues:

  • It is not very discoverable
  • It reuses the LINQ Select operator for something that could be argued is not selecting

The second issue could be addressed with a new method, but the discoverability issue would still remain.

Proposal

A new proposal is to use a pattern similar to LINQ OrderBy:

customers.Include(c => c.Contact).ThenInclude(c => c.Address);
customers.Include(c => c.Orders).ThenInclude(o => o.OrderDetails);

This means that:

  • Lambdas can be valid dotted property expressions
  • It works the same for references and collections

The example from above would now look like this:

categories
    .Include(c => c.Products).ThenInclude(p => p.Reviews).ThenInclude(r => r.Author)
    .Include(c => c.Products).ThenInclude(p => p.Supplier);

Discussion

Please comment on this issue to provide feedback, ask questions, etc.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:31 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
jnm2commented, Mar 14, 2015

I’m actually excited about ThenIncludes, where Includes resets back to the root. It’s clean and genius. Why didn’t I think of that what I was writing helpers?

0reactions
ajcvickerscommented, May 15, 2017

We are closing this issue because no further action is planned for this issue. If you still have any issues or questions, please log a new issue with any additional details that you have.

Read more comments on GitHub >

github_iconTop Results From Across the Web

january-8-2015-design-review-board-meeting- ...
SUMMARY OF MOTIONS. TOWN OF MOUNTAIN VILLAGE. DESIGN REVIEW BOARD MEETING. THURSDAY, JANUARY 8, 2015. Call to Order. Acting Chairman, David Eckman, ...
Read more >
C# Design Notes for Jan 21, 2015 · Issue #98 · dotnet/roslyn
We've made it three hours without slippery slopes coming up! Agenda. This is the first design meeting for the version of C# coming...
Read more >
Meeting Minutes January 8, 2015
MINUTES OF JANUARY 8, 2015. A meeting of the Long Island Rail Road Commuter Council (LIRRCC) was convened at 4:30 p.m. on January...
Read more >
1 CITY OF WILMINGTON HISTORIC PRESERVATION ...
HISTORIC PRESERVATION COMMISSION MEETING MINUTES. January 8, 2015. A regular meeting of the Wilmington Historic Preservation Commission was held on January ...
Read more >
The Woodlands Township
VILLAGE OF INDIAN SPRINGS. THE WOODLANDS TOWNSHIP. RESIDENTIAL DESIGN REVIEW COMMITTEE. MEETING MINUTES. January 8, 2015. 2801 Technology Forest Boulevard.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found