Skip to content

Commit

Permalink
Entity equality support for non-anonymous DTOs
Browse files Browse the repository at this point in the history
MemberAssignmentBinding only for now.

Fixes #16789
  • Loading branch information
roji committed Jul 31, 2019
1 parent b9653e8 commit 53d81e0
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,39 +331,57 @@ protected override Expression VisitNew(NewExpression newExpression)
/// </summary>
protected override Expression VisitMemberInit(MemberInitExpression memberInitExpression)
{
var newExpression = (NewExpression)Visit(memberInitExpression.NewExpression);
var newExpression = VisitAndConvert(memberInitExpression.NewExpression, nameof(VisitMemberInit));
if (newExpression == null)
{
return null;
}

var newBindings = new MemberAssignment[memberInitExpression.Bindings.Count];
var newBindings = new MemberBinding[memberInitExpression.Bindings.Count];
for (var i = 0; i < newBindings.Length; i++)
{
var memberAssignment = (MemberAssignment)memberInitExpression.Bindings[i];
if (_clientEval)
if (memberInitExpression.Bindings[i].BindingType != MemberBindingType.Assignment)
{
newBindings[i] = memberAssignment.Update(Visit(memberAssignment.Expression));
return null;
}
else
{
var projectionMember = _projectionMembers.Peek().Append(memberAssignment.Member);
_projectionMembers.Push(projectionMember);

var visitedExpression = Visit(memberAssignment.Expression);
if (visitedExpression == null)
{
return null;
}
newBindings[i] = VisitMemberBinding(memberInitExpression.Bindings[i]);

newBindings[i] = memberAssignment.Update(visitedExpression);
_projectionMembers.Pop();
if (newBindings[i] == null)
{
return null;
}
}

return memberInitExpression.Update(newExpression, newBindings);
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override MemberAssignment VisitMemberAssignment(MemberAssignment memberAssignment)
{
if (_clientEval)
{
return memberAssignment.Update(Visit(memberAssignment.Expression));
}

var projectionMember = _projectionMembers.Peek().Append(memberAssignment.Member);
_projectionMembers.Push(projectionMember);

var visitedExpression = Visit(memberAssignment.Expression);
if (visitedExpression == null)
{
return null;
}

_projectionMembers.Pop();
return memberAssignment.Update(visitedExpression);
}

// TODO: Debugging
private void VerifySelectExpression(ProjectionBindingExpression projectionBindingExpression)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,39 +209,51 @@ protected override Expression VisitNew(NewExpression newExpression)

protected override Expression VisitMemberInit(MemberInitExpression memberInitExpression)
{
var newExpression = (NewExpression)Visit(memberInitExpression.NewExpression);
var newExpression = VisitAndConvert(memberInitExpression.NewExpression, nameof(VisitMemberInit));
if (newExpression == null)
{
return null;
}

var newBindings = new MemberAssignment[memberInitExpression.Bindings.Count];
var newBindings = new MemberBinding[memberInitExpression.Bindings.Count];
for (var i = 0; i < newBindings.Length; i++)
{
var memberAssignment = (MemberAssignment)memberInitExpression.Bindings[i];
if (_clientEval)
if (memberInitExpression.Bindings[i].BindingType != MemberBindingType.Assignment)
{
newBindings[i] = memberAssignment.Update(Visit(memberAssignment.Expression));
return null;
}
else
{
var projectionMember = _projectionMembers.Peek().Append(memberAssignment.Member);
_projectionMembers.Push(projectionMember);

var visitedExpression = Visit(memberAssignment.Expression);
if (visitedExpression == null)
{
return null;
}
newBindings[i] = VisitMemberBinding(memberInitExpression.Bindings[i]);

newBindings[i] = memberAssignment.Update(visitedExpression);
_projectionMembers.Pop();
if (newBindings[i] == null)
{
return null;
}
}

return memberInitExpression.Update(newExpression, newBindings);
}

protected override MemberAssignment VisitMemberAssignment(MemberAssignment memberAssignment)
{
if (_clientEval)
{
return memberAssignment.Update(Visit(memberAssignment.Expression));
}

var projectionMember = _projectionMembers.Peek().Append(memberAssignment.Member);
_projectionMembers.Push(projectionMember);

var visitedExpression = Visit(memberAssignment.Expression);
if (visitedExpression == null)
{
return null;
}

_projectionMembers.Pop();
return memberAssignment.Update(visitedExpression);
}

// TODO: Debugging
private void VerifyQueryExpression(ProjectionBindingExpression projectionBindingExpression)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,39 +232,51 @@ protected override Expression VisitNew(NewExpression newExpression)

protected override Expression VisitMemberInit(MemberInitExpression memberInitExpression)
{
var newExpression = (NewExpression)Visit(memberInitExpression.NewExpression);
var newExpression = VisitAndConvert(memberInitExpression.NewExpression, nameof(VisitMemberInit));
if (newExpression == null)
{
return null;
}

var newBindings = new MemberAssignment[memberInitExpression.Bindings.Count];
var newBindings = new MemberBinding[memberInitExpression.Bindings.Count];
for (var i = 0; i < newBindings.Length; i++)
{
var memberAssignment = (MemberAssignment)memberInitExpression.Bindings[i];
if (_clientEval)
if (memberInitExpression.Bindings[i].BindingType != MemberBindingType.Assignment)
{
newBindings[i] = memberAssignment.Update(Visit(memberAssignment.Expression));
return null;
}
else
{
var projectionMember = _projectionMembers.Peek().Append(memberAssignment.Member);
_projectionMembers.Push(projectionMember);

var visitedExpression = Visit(memberAssignment.Expression);
if (visitedExpression == null)
{
return null;
}
newBindings[i] = VisitMemberBinding(memberInitExpression.Bindings[i]);

newBindings[i] = memberAssignment.Update(visitedExpression);
_projectionMembers.Pop();
if (newBindings[i] == null)
{
return null;
}
}

return memberInitExpression.Update(newExpression, newBindings);
}

protected override MemberAssignment VisitMemberAssignment(MemberAssignment memberAssignment)
{
if (_clientEval)
{
return memberAssignment.Update(Visit(memberAssignment.Expression));
}

var projectionMember = _projectionMembers.Peek().Append(memberAssignment.Member);
_projectionMembers.Push(projectionMember);

var visitedExpression = Visit(memberAssignment.Expression);
if (visitedExpression == null)
{
return null;
}

_projectionMembers.Pop();
return memberAssignment.Update(visitedExpression);
}

// TODO: Debugging
private void VerifySelectExpression(ProjectionBindingExpression projectionBindingExpression)
{
Expand Down
Loading

0 comments on commit 53d81e0

Please sign in to comment.