Let's say you have this:
public class Category {
public virtual ICollection<Product> Products {get; set; }
}
public class Product {
….
public int SortIndex {get; set; }
...
}
Normally you would do something like this to include the products:
DbSet<Category>.Include(c => c.Products)
When you get the category entity it will have also products loaded.
But can these products be loaded in a specific order in the include?
Some kind of overload in include where you can define some kind of OrderBy:
DbSet<Category>.Include(c => c.Products, orderby: p => p.SortIndex)
Is this something that would be possible or maybe in a near future?
Note for triage: related: #9067
@divega to think about this.
This would be great indeed, especially in the near future.
Right now I have the choice to sort data after querying the database, or query it multiple times (in loops in complex queries) and stitch the ordered collections to their objects. Both feels (and, to be fair, is) ridiculous and a waste of resources.
Hi @ajcvickers and @divega, as the 3.0.0 preview9 has been released, and can't find this in the change-log, any idea when we can get this feature added, please?
@tonmoypaul we used to have this assigned to the 3.0.0 release to investigate what it could look like, but we moved it back to the backlog a few months ago. We haven't done the planning for 5.0 yet, so it isn't clear when we will get to it. There many competing priorities.
Note for triage: after giving this some thought removing milestone so that we can decide where/how to track this of find possible duplicates.
This feels very similar/complementary to filtered include thought without full-fledged support for ordered collections, the feature would have limited use.
addressed by filtered include feature
DbSet<Category>.Include(c => c.Products.OrderBy(p => p.SortIndex))
Most helpful comment
addressed by filtered include feature