-
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
Specified cast is not valid #4308
Comments
Can someone tell me if this is a bug? It just seems too simple to be an undocumented issue, but it's cropping up everywhere in my project. |
This seems to work:
I suppose it makes sense - you have to explicitly convert it to a decimal to get EF to do so. EF6 was able to infer this I guess. I need the |
In my example, I have a
Time
class with aMinutes
field defined using theshort
data type.If I try to get the total decimal hours like this:
var totalHours = _dbContext.Times.Sum(t => t.Minutes / 60m);
I get the error:
An exception of type 'System.InvalidCastException' occurred in EntityFramework.Core.dll but was not handled in user code. Additional information: Specified cast is not valid.
This, however, works fine:
var totalHours = _dbContext.Times.Sum(t => t.Minutes / 60);
The text was updated successfully, but these errors were encountered: