Skip to content

Commit

Permalink
Entity equality support for non-anonymous DTOs
Browse files Browse the repository at this point in the history
Also various modifications to support MemberMemberBinding better.

Fixes #16789
  • Loading branch information
roji committed Jul 27, 2019
1 parent b9653e8 commit 043a4e4
Show file tree
Hide file tree
Showing 10 changed files with 309 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,45 +323,45 @@ protected override Expression VisitNew(NewExpression newExpression)
return newExpression.Update(newArguments);
}

/// <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 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)
newBindings[i] = VisitMemberBinding(memberInitExpression.Bindings[i]);
if (newBindings[i] == null)
{
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;
}
return memberInitExpression.Update(newExpression, newBindings);
}

newBindings[i] = memberAssignment.Update(visitedExpression);
_projectionMembers.Pop();
}
protected override MemberAssignment VisitMemberAssignment(MemberAssignment memberAssignment)
{
if (_clientEval)
{
return memberAssignment.Update(Visit(memberAssignment.Expression));
}

return memberInitExpression.Update(newExpression, newBindings);
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,37 +209,43 @@ 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)
newBindings[i] = VisitMemberBinding(memberInitExpression.Bindings[i]);
if (newBindings[i] == null)
{
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;
}
return memberInitExpression.Update(newExpression, newBindings);
}

newBindings[i] = memberAssignment.Update(visitedExpression);
_projectionMembers.Pop();
}
protected override MemberAssignment VisitMemberAssignment(MemberAssignment memberAssignment)
{
if (_clientEval)
{
return memberAssignment.Update(Visit(memberAssignment.Expression));
}

return memberInitExpression.Update(newExpression, newBindings);
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,37 +232,43 @@ 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)
newBindings[i] = VisitMemberBinding(memberInitExpression.Bindings[i]);
if (newBindings[i] == null)
{
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;
}
return memberInitExpression.Update(newExpression, newBindings);
}

newBindings[i] = memberAssignment.Update(visitedExpression);
_projectionMembers.Pop();
}
protected override MemberAssignment VisitMemberAssignment(MemberAssignment memberAssignment)
{
if (_clientEval)
{
return memberAssignment.Update(Visit(memberAssignment.Expression));
}

return memberInitExpression.Update(newExpression, newBindings);
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
Expand Down
Loading

0 comments on commit 043a4e4

Please sign in to comment.