score:1
Your concern about size of the query and size of the result set are tangible.
As @BrokenGlass mentioned EF doesn't allow you doing filtering or ordering on includes. If you want to order or filter relations you must use projection either to anonymous type or custom (non mapped) type:
var query = db.Leagues
.Where(l => l.URLPart.Equals(leagueName))
.Select(l => new
{
League = l,
Events = l.LeagueEvents.Where(...)
.OrderBy(...)
.Take(3)
.Select(e => e.Event)
...
});
score:0
Unfortunately EF doesn't allow to selectively load related entities using its navigation properties, it will always load all Foos
if you specify Include("Foo")
.
You will have to do a join on each of the related entities using your Where()
clauses as filters where they apply.
Source: stackoverflow.com
Related Articles
- c# Linq or code to extract groups from a single list of source data
- The data source does not support server-side data paging
- How does LINQ expression syntax work with Include() for eager loading
- I am wondering about the state of connection and impact on code performance by 'yield' while iterating over data reader object
- Syntax to execute code block inside Linq query?
- System.ArgumentException: Complex DataBinding accepts as a data source either an IList or an IListSource
- Why is my code doing lazy loading even after I turned it off at every possible point?
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- Does Queryability and Lazy Loading in C# blur the lines of Data Access vs Business Logic?
- How does linq actually execute the code to retrieve data from the data source?
- LINQ Source Code Available
- .NET 4 Code Contracts: "requires unproven: source != null"
- Is there a way to speed up this code that finds data changes in two XML files?
- Performance issue loading data from CRM
- The given value of type String from the data source cannot be converted to type int of the specified target column
- Merge duplicate data without affecting others in LINQ code
- Use a linq query as microsoft local report Data Source (WinForms)
- Data Loading Strategy/Syntax in EF4
- At what point is a LINQ data source determined?
- EF Code first Eager loading and OrderBy problem
- creating Linq to sqlite dbml from DbLinq source code
- read icollection data using LINQ in C# code
- updating data in many-to-many relationship in entity framework in code first existing database
- Linq to sql as object data source - designer problem with partial classes
- How can i copy data table records of different field name based on mapping list evaluating condition on source data table?
- C# LINQ How to get a data source from a db?
- Using LINQ query result for data source for GridControl c#
- how to combine two data source into one?
- How to avoid OutOfMemoryException while loading large chunks of data from a database?
- Query XML source in LinqPad using lambda syntax
- LINQ: How to rewrite WHERE clause to avoid: Local sequence cannot be used in LINQ to SQL
- Apply filters to a table based on conditions using LINQ and MVC C#
- How to get parent node in a tree structure like this
- How to rollback transaction using LINQ-to-SQL in entity framework?
- Error with converting int to string in Linq to entities
- Obtaining multiple fields with LINQ group statement
- Enumerable.Sum() overflowing
- LINQ query optimization?
- Sort a list and all its nested objects using LINQ
- Linq Recursive Search
- Entity Framework - Conditionally adding columns into group by
- Find value via property name in json.net?
- How to get both key and value from list separately with linq query
- How can I ignore / skip 'n' elements while sorting string in a lexicographical order
- How to restrict LINQ query to marketing lists of a given campaign?
- Cast IQueryable<EntityObject> to IQueryable<Specific>
- Convert a List of object to a Tuple array
- Merging two lists in linq without anonymous type
- Is LINQ to Dataset subset of LINQ to EF or these two are independent?
- LINQ To SQL exception: Local sequence cannot be used in LINQ to SQL implementation