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
"No coercion operator is defined" with dynamically generated selection expression #11165
Comments
@samfozz Looking in the debugger, the difference in the expression trees is in the type of the null constant used int the conditional. Changing it to type object in the explicitly built tree results in identitical expression trees and it then works with EF query: var mainAssignment = Expression.Bind(navProp,
Expression.Condition(
Expression.MakeBinary(ExpressionType.NotEqual, Expression.MakeMemberAccess(parent, navProp),
Expression.Constant(null)), // <-- Change is here
Expression.MemberInit(Expression.New(ctor), subAssignments),
Expression.Constant(null, navProp.PropertyType))); Leaving this issue open to discuss in triage if this is something we need to address in the query pipeline. |
@ajcvickers Sorry I didn't spot that myself - Thanks for this! |
- Introduce rewrite for reference navigation (which was being done in nav expansion before) - Disallow rewrite for owned entities (forces client eval for now) See #11485 - Streamline rewrite between Equals method & `==` - Convert to false when 2 unrelated entityTypes are being compared Resolves #11165
- Introduce rewrite for reference navigation (which was being done in nav expansion before) - Disallow rewrite for owned entities (forces client eval for now) See #11485 - Streamline rewrite between Equals method & `==` - Convert to false when 2 unrelated entityTypes are being compared Resolves #11165
- Introduce rewrite for reference navigation (which was being done in nav expansion before) - Disallow rewrite for owned entities (forces client eval for now) See #11485 - Streamline rewrite between Equals method & `==` - Convert to false when 2 unrelated entityTypes are being compared Resolves #11165
- Introduce rewrite for reference navigation (which was being done in nav expansion before) - Disallow rewrite for owned entities (forces client eval for now) See #11485 - Streamline rewrite between Equals method & `==` - Convert to false when 2 unrelated entityTypes are being compared Resolves #11165
- Introduce rewrite for reference navigation (which was being done in nav expansion before) - Disallow rewrite for owned entities (forces client eval for now) See #11485 - Streamline rewrite between Equals method & `==` - Convert to false when 2 unrelated entityTypes are being compared Resolves #11165
I'm trying to generate a selection expression at runtime using System.Linq.Expressions.
This expression selects a navigation property - I am able to generate an expression equivalent to the following with no problems and it works well correctly :
However, the issue seems to come in when I attempt to add a null check to the generated expression, like this :
This expression when manually coded as above works fine, But when I generate one using Expression.Lambda, I get the "No coercion operator" error executing the expression.
I've created an example of the issue here ( this uses the Microsoft.EntityFramworkCore 2.0.1 / Microsoft.EntityFramworkCore.InMemory / 2.0.1 nuget packages ) - This is a full dotnet core app with the dynamic expression generation being in the MakeDynamicExpression method there.
https://gist.github.com/samfozz/58c799d88b24f6c3f70c5a6dff5b57c1
I've can't seem to find the difference between the generated expression and the hard coded one - they are identical in debug view, and I have not been able to find the difference inspecting the objects in the debugger. The generated expression works correctly when compiled to a Func<TEntity,object>.
Steps to reproduce
See here :
https://gist.github.com/samfozz/58c799d88b24f6c3f70c5a6dff5b57c1
Further technical details
EF Core version: 2.0.1
Database Provider: InMemory
Operating system: Windows 10
IDE: Visual Studio 2017
The text was updated successfully, but these errors were encountered: