You are accessing the
DayOfWeek property from a
DateTime reference in the query.
Entity Framework "doesn't know" how to translate that to SQL thus in the first piece of code you getting an exception.
And in the second piece it is working after you have fetch all of the data from database at the
.ToList() call, and the
.Where filtering is happening in the memory.
If you wish to implement that logic on the database side, you will have to write your own SQL statement.
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- LINQ Source Code Available
- linq - how do you do a query for items in one query source that are not in another one?
- How can I write the following code more elegantly using LINQ query syntax?
- How to dynamic add filters to a LINQ query against an Odata Source in C#
- C# Linq query help removing foreach loops creating cleaner code
- Use a linq query as microsoft local report Data Source (WinForms)
- Determine the source DataContext for a Linq to Sql query
- LINQ query returns old results when source list is re-initialized
- How to get SQL query into LINQ form in C# code
- How can I code a Linq query to do an upward Include?
- creating Linq to sqlite dbml from DbLinq source code
- Identify source of linq to sql query
- NHibernate LINQ query performance, which code fragment is better?
- Linq sub query when using a repository pattern with EF code first
- Using LINQ query result for data source for GridControl c#
- convert linq to object query to sql query (no linq to sql code or datacontext)
- Getting 'Data source is an invalid type' when binding Linq query to Gridview
- DayOfWeek in LINQ query
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- Converting foreach loop to LINQ query breaks code
- C# code for equivalent LINQ query
- How do I determine the source of unpredictable LINQ query results?
- How to Select top (5) contributors group by Business type code in c# linq query
- How can I code numerous MIN functions into one LINQ to DataSet query
- Avoiding repeating code with Linq query + optional params
- Unreachable expression code in LINQ query
- Reduce the line of code for this LINQ query
- source code for LINQ 101 samples
- How to build custom PLINQO query by multiple id's?
- Adding to two different lists from one LINQ query
- Combining parts of one list into another List LINQ
- Linq with union on 3 tables
- How to retrieve recurring costs using Linq
- Asp.net MVC3 with LINQ to SQL on multiple identical tables
- LinqPad Entity Framework and the NullExceptionReference
- Doubts about how to read XML with Linq
- System.Linq.Dynamic.DynamicExpression.ParseLambda issue with Select() command
- Dynamic library (System.Linq.Dynamic) SQL LIKE Operator
- How to use nullable built-in variables in LINQ?
- Default Value for Join Predicate as Method Parameter
- Challenge: LINQ to Convert Hierarchy XML to Linked Objects
- Casting string to IEnumerable<object>
- IGrouping <int, Customer> does not contain a definition for Points etc
- Adding relations in code only
- I use Distinct in my complex lambda query but is not work
- Handling Null objects with AutoMapper
- Convert SQL to linQ Group By having count and sum
- How to .GroupBy multiple columns LINQ/Projection?