question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 issue

EF 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.IEnumerable1[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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ajcvickerscommented, Sep 9, 2021

@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.

1reaction
rojicommented, Sep 9, 2021

@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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found