-
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
TypeMapping bug in translation plugin #27075
Comments
This is bug in the plug-in. |
But it isn't the plug-in that's constructing the original One workaround is to break down the private SqlExpression AdjustConversion(SqlExpression sqlExpression)
{
if (sqlExpression is SqlUnaryExpression { OperatorType: ExpressionType.Convert, TypeMapping: null } sqlUnaryExpression)
{
var mapping = _typeMappingSource.FindMapping(sqlExpression.Type);
if (mapping is not null)
return new SqlUnaryExpression(sqlUnaryExpression.OperatorType, sqlUnaryExpression.Operand, sqlUnaryExpression.Type, mapping);
}
return sqlExpression;
} But it will only work if .RowNumber((long)b.BlogId)+1) I don't suppose that the plugin developer is expected to go down the tree recursively to break down and construct everything again... |
@virzak this isn't about recursively breaking down anything. Translators have the responsibility of producing a tree where type mappings are set on the nodes, whereas you're returning nodes with null mappings (source). The important point is that a node's mapping isn't always determined based on what it contains, but also on what contains it. For example, in the expression In your specific case with RowNumber, I don't think there's any inference involved. If that's the case and the type mapping should solely be determined by what's inside the node, then you need to tell EF Core to calculate that by calling SqlExpressionFactory.ApplyDefaultTypeMapping. That method basically sets the type mapping to correspond to the CLR type of the expression node (unless it already has a type mapping). I suggest looking at some translation code in one of the providers to see how it all works. |
Calling code that causes the issue. Cast to
long
is the problem, works fine without it:Translator:
Please run
typemapping-bug-repro
branch of my samples fork to reproduce:https://github.com/virzak/EntityFramework.Docs/tree/typemapping-bug-repro/samples/core/SqlServer
Stack traces
EF Core version: 6
Database provider: SqlServer
Target framework: .NET 6.0
Operating system: Windows 11
IDE: Visual Studio 2022 17.1.0 Preview 1.1
The text was updated successfully, but these errors were encountered: