-
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
Support translation of member access on properties mapped by value conversion #20721
Comments
It was client evaluated before. |
@smitpatel Interesting! Is there a way to get the desired behavior, either through adding custom code or by allowing client evaluation for this specific case? |
@smitpatel The issue is that a ColumnExpression cannot be generated for Address.Street, while it can for Address. In RelationalSqlTranslatingExpressionVisitor, TryBindMember succeeds for Address, but then fails for Address.Street due to the Expression having to be an EntityReferenceExpression. Can you provide some guidance on how I can tackle this? protected override Expression VisitMember(MemberExpression memberExpression)
{
Check.NotNull(memberExpression, nameof(memberExpression));
var innerExpression = Visit(memberExpression.Expression);
return TryBindMember(innerExpression, MemberIdentity.Create(memberExpression.Member))
?? (TranslationFailed(memberExpression.Expression, Visit(memberExpression.Expression), out var sqlInnerExpression)
? null
: Dependencies.MemberTranslatorProvider.Translate(sqlInnerExpression, memberExpression.Member, memberExpression.Type));
}
private Expression TryBindMember(Expression source, MemberIdentity member)
{
if (!(source is EntityReferenceExpression entityReferenceExpression))
{
return null;
}
var entityType = entityReferenceExpression.EntityType;
var property = member.MemberInfo != null
? entityType.FindProperty(member.MemberInfo)
: entityType.FindProperty(member.Name);
return property != null ? BindProperty(entityReferenceExpression, property) : null;
} |
@smitpatel Of course, I can replace MemberExpressions in the original expression tree with a custom expression when it follows a specific pattern to enforce custom handling. But I was hoping to change EntityFrameworkCore's code to fix this. |
@bdebaere This particular case is covered by #4021 since using the conversion is basically a workaround here. Beyond this, we will keep this open for translating accesses on converted objects like this. However, the cases where this will work are probably going to be somewhat constricted, at least at first, since the conversion can do just about anything and not all accesses will be possible/easy to translate. |
See #10434 |
Filtering on a complex type is no longer possible in EntityFrameworkCore 3.1.3. Consider the code below. This code used to work with EntityFrameworkCore 2.2 without a problem. The reason why I am not using OwnsOne is because I want to apply a conversion as the entity is saved as a JSON in one column, and I want Address to always be visible (i.e. not something to use .Include() on). Am I doing something wrong here?
Further technical details
EF Core version: 3.1.3
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.1
Operating system: Windows
IDE: Visual Studio 2019 16.3
The text was updated successfully, but these errors were encountered: