Expression of type 'Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1[System.Boolean]' cannot be used for return type 'System.Collections.Generic.IEnumerable`1[System.Object]'
See original GitHub issueEF Core version: 5.0.9 Database provider: Npgsql.EntityFrameworkCore.PostgreSQL 5.0.7 Target framework: .NET 5.0 Operating system: Windows 10 IDE: Visual Studio 2019
I am working with Dynamic Linq, when working with strings I have no problems, when dealing with bool’s, i got the following error:
Expression of type ‘Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable1[System.Boolean]' cannot be used for return type 'System.Collections.Generic.IEnumerable
1[System.Object]’
For testing purpuses I wrote three cases:
IQueryable iQueryable = dbContext.MyEntity.AsQueryable();
var one = iQueryable.Select("MyBooleanField").Distinct();
var two = iQueryable.Select("MyBooleanField").Distinct().Cast<object>();
var three = iQueryable.Select("MyBooleanField").Distinct().Cast<bool>();
one
and three
work fine, two
leads to the above exception.
What’s the problem?
I made a sample: EF-Test.zip
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Cannot be used for return type error when querying via any ...
First I want to to apologize because you are right. Your query is correct! Second I created an app and found the problem:....
Read more >Invalidoperationexception: the LINQ expression
Hi, I have the message System.InvalidOperationException: The LINQ expression 'DbSet<Developer>() .Where(d => d.Calcul < 0)' could not be ...
Read more >SELECT Distinct CarMakes from table using LINQ
I have a table that has CarMake, CarModels and several other columns. I wan to select distinct carmake only.
Read more >SqlFunctionExpression Class
An expression that represents a function call in a SQL tree. This type is typically used by database providers (and other extensions).
Read more >Entity Framework crashing when using linq Any() method
Convert(Expression expression, Type type, MethodInfo method)\r\n at Microsoft.EntityFrameworkCore.Storage.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@emaborsa As @roji said, please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.
@emaborsa it’s not quite clear what you’re doing here (e.g. where does the Select overload with a string argument come from?). Can you please submit a runnable code sample rather than a fragment?