-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Count() throws InvalidCastException in specific cases #16722
Comments
@fschlaef All these are cases where the projection cannot (currently) be translated to SQL. In 3.0, we allow a final projection to be evaluated on the client, but then when the aggregate ( The plan for 3.0 is to throw an exception with a clearer message for this. (@smitpatel #16133 or is #15937 this case?) For the future, putting this on the backlog to investigate silently dropping the projection when discarded by the final query anyway. However, we need to be careful about side-effects. |
This has been fixed in my current work of Nav rewrite. |
@smitpatel Merge before Monday?
The mountain isn't going anywhere.... 😉
|
🌨 ⛈ 🌩 🌧 keep on moving... |
What does this statement refer to? Is it fixed or not? According to the issue milestone it is not? I will put another +1 on this issue because this will be a big problem for everyone implementing a basic paginated list. Example: var entries =
(from c in context.Customers
select new CustomerListItem
{
c.Id,
c.Name,
ClientEvalProperty = // Some client eval expression
});
var viewModel = new ViewModel
{
Entries = entries.Skip(..).Take(..).ToList(),
Total = entries.Count() // Boom => Crash!
}; |
@davidroth - We believe that this issue has been fixed in latest daily builds. |
@smitpatel Confirmed working with 3.0.0-rc1 👍 |
@smitpatel Same here 👍 Works in 3.0.0-rc1.19424.9 |
Need to add a test for this. |
This still fails: Unable to cast object of type 'Microsoft.EntityFrameworkCore.Query.SqlExpressions.SqlFunctionExpression' to type 'System.Linq.Expressions.ConstantExpression'. Specifically with .Distinct() which obviously shouldn't be stopping any query from being executed properly. Or to put another way, if a query can execute fine and materialize as the last step without .Distinct, it certainly can with it since it's just SELECT DISTINCT ... instead of SELECT ... |
Hi, I confirm problem still exists - is Exception for Count with Select().Distinct() .... Please FIX IT! |
When using
.Count()
following specific operations, the following exception is thrown :Steps to reproduce
There are multiple ways to reproduce this error :
CodeFormat
being simply this :Weirdly enough, doing
.ToList()
doesn't throw.Further technical details
EF Core version: 3.0.0-preview7.19365.7
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10 x64
IDE: Visual Studio 2019 16.2.0 Preview 4.0
The text was updated successfully, but these errors were encountered: