Open mojtabakaviani opened 2 months ago
.NET itself doesn't have a Sum() extension method over short (see Sum() overloads), so your code doesn't compile. Are you trying to add your own overload of Sum or similar? If so, that won't work.
In general, rather than posting a couple snippets (which don't compile), when submitting an issue, please always include an actual runnable code sample, as a console program.
efcore support Sum() overloading? I cast qty to int but not working and need change data types.
I'd suggest simply changing the type to int - that would likely be the simplest solution here.
There seems to be no other way at the moment, but the problem is the unnecessary space in the database that appears in the large number of records.
I'm not sure exactly how much data you're deailng with, but in many/most cases the actual difference between an int16 and an int32 would be negligible. Otherwise, you can use SQL querying to write the SQL you want, without LINQ, for the specific query where you need to.
I'll keep this issue open to track providing some way to express this. Another way to go here is to propose adding Sum() overloads to .NET itself (for short, byte...).
Thank you, @roji. I am looking forward to the removal of this restriction.
File a bug
Failing to project query with sum of subquery that select short properties to get totals. with int properties work properly and not work id cast type.
Stack traces
Provider and version information
EF Core version: 8.0.7 Database provider: Microsoft.EntityFrameworkCore.SqlServer,Npgsql.EntityFrameworkCore.PostgreSQL Target framework: .NET 8.0 Operating system: Windows 11 IDE: VS Code