Is there any way to query with EFCore 3.1 by joining multiple fields together with String.Format, or $"{}" or just the traditional "" + "" + ""?
I have this code:
await this.Db.ACoolDbSet.Where(y => y.Plums + " " + y.Pears == "LOL").ToListAsync();
Plums
and Pears
are integers.
It results in this error:
System.InvalidOperationException: 'Null TypeMapping in Sql Tree'
Is this expected?
This exception was originally thrown at this call stack:
Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.SqlTypeMappingVerifyingExpressionVisitor.VisitExtension(System.Linq.Expressions.Expression)
System.Linq.Expressions.Expression.Accept(System.Linq.Expressions.ExpressionVisitor)
System.Linq.Expressions.ExpressionVisitor.Visit(System.Linq.Expressions.Expression)
Microsoft.EntityFrameworkCore.Query.SqlExpressions.SqlBinaryExpression.VisitChildren(System.Linq.Expressions.ExpressionVisitor)
System.Linq.Expressions.ExpressionVisitor.VisitExtension(System.Linq.Expressions.Expression)
Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.SqlTypeMappingVerifyingExpressionVisitor.VisitExtension(System.Linq.Expressions.Expression)
System.Linq.Expressions.Expression.Accept(System.Linq.Expressions.ExpressionVisitor)
System.Linq.Expressions.ExpressionVisitor.Visit(System.Linq.Expressions.Expression)
Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.Translate(System.Linq.Expressions.Expression)
Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateExpression(System.Linq.Expressions.Expression)
...
[Call Stack Truncated]
Adding y.Plums.ToString() and y.Pears.ToString() resolves the issue. String.Format and $"{}" are still not working unfortunately
Try this
await this.Db.ACoolDbSet.Where(y => y.Plums.ToString() + " " + y.Pears.ToString() == "LOL").ToListAsync();
string interpolation is working now in EF Core 3.1
await this.Db.ACoolDbSet.Where(y => $"{y.Plums} {y.Pear}" == "LOL").ToListAsync();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With