score:2
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.
Source: stackoverflow.com
Related Query
- 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
More Query from same tag
- Is Access to Modified Closure warnings valid for string variable?
- Filtering folders from a list when using LINQ to sort to find the oldest file
- How to use LINQ to return a query result to a dictionary
- Entity Framework - Cascade deleting
- Auto load child items from immediate parent based on XML attribute
- Need to get a particular value from XML
- Linq query and group by data from table which has one to many relationship?
- How to combine List items
- Compare 2 Columns in DataTable to 2 Columns in List and build a new List with certain criteria
- c# Add some values at List
- Difference in how LINQ to Entities and LINQ to Objects handle casts
- How to filter on a xml node name keeping the tree structure?
- how to check given date exist in month or not?
- How to find duplicates in a List<T> quickly, and update the original collection
- Simple Edit/Update actions using LINQ. Isn't my code a bit wrong?
- Building a custom|progressive query in LINQ?
- LINQ only returns one item in collection
- How to return this format this JSON into an array of strings
- Var vs IEnumerable when it comes to Entity Framework
- Remove multiple rows from table with a LINQ query
- How to calculate a running total using linq
- Find common items in list of lists of strings
- Query from relational tables with conditions using Entity Framework c#
- How to check in all visible rows CELLs for string.IsNullOrEmpty and IsDateEmpty
- Retrieving data from a second table if it has a record with the Id from another table
- Multiple tables in lambda expression
- Unable to edit Foreign Key Property
- How can I concatenate all the column values in a row, and then concatenate all rows in a DataTable into a single string?
- F# is unable to infer type arguments after annotation
- Query many-to-many relationship with linq c#