Skip to content
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

Query: Skip updating NewExpression without ctor #18391

Merged
merged 1 commit into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,12 @@ protected override Expression VisitTypeBinary(TypeBinaryExpression typeBinaryExp

protected override Expression VisitNew(NewExpression newExpression)
{
// For .NET Framework only. If ctor is null that means the type is struct and has no ctor args.
if (newExpression.Constructor == null)
{
return newExpression;
}

var newArguments = new List<Expression>();
foreach (var argument in newExpression.Arguments)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ protected override Expression VisitExtension(Expression extensionExpression)

protected override Expression VisitNew(NewExpression newExpression)
{
// For .NET Framework only. If ctor is null that means the type is struct and has no ctor args.
if (newExpression.Constructor == null)
{
return newExpression;
}

if (newExpression.Arguments.Count == 0)
{
return newExpression;
Expand Down
6 changes: 6 additions & 0 deletions src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@ private Expression GetGroupingKey(Expression key, List<Expression> groupingExpre
switch (key)
{
case NewExpression newExpression:
// For .NET Framework only. If ctor is null that means the type is struct and has no ctor args.
if (newExpression.Constructor == null)
{
return newExpression;
}

var arguments = new Expression[newExpression.Arguments.Count];
for (var i = 0; i < arguments.Length; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ private Expression TranslateGroupingKey(Expression expression)
switch (expression)
{
case NewExpression newExpression:
// For .NET Framework only. If ctor is null that means the type is struct and has no ctor args.
if (newExpression.Constructor == null)
{
return newExpression;
}

if (newExpression.Arguments.Count == 0)
{
return newExpression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ protected override Expression VisitExtension(Expression extensionExpression)

protected override Expression VisitNew(NewExpression newExpression)
{
// For .NET Framework only. If ctor is null that means the type is struct and has no ctor args.
if (newExpression.Constructor == null)
{
return newExpression;
}

if (newExpression.Arguments.Count == 0)
{
return newExpression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@ private Expression TranslateGroupingKey(Expression expression)
switch (expression)
{
case NewExpression newExpression:
// For .NET Framework only. If ctor is null that means the type is struct and has no ctor args.
if (newExpression.Constructor == null)
{
return newExpression;
}

if (newExpression.Arguments.Count == 0)
{
return newExpression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ protected override Expression VisitConstant(ConstantExpression constantExpressio

protected override Expression VisitNew(NewExpression newExpression)
{
// For .NET Framework only. If ctor is null that means the type is struct and has no ctor args.
if (newExpression.Constructor == null)
{
return newExpression;
}

var visitedArgs = Visit(newExpression.Arguments);
var visitedExpression = newExpression.Update(visitedArgs.Select(Unwrap));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp

protected override Expression VisitNew(NewExpression newExpression)
{
// For .NET Framework only. If ctor is null that means the type is struct and has no ctor args.
if (newExpression.Constructor == null)
{
return newExpression;
}

var arguments = new Expression[newExpression.Arguments.Count];
for (var i = 0; i < newExpression.Arguments.Count; i++)
{
Expand All @@ -382,6 +388,13 @@ private bool ReconstructAnonymousType(Expression currentRoot, NewExpression newE
{
replacement = null;
var changed = false;

// For .NET Framework only. If ctor is null that means the type is struct and has no ctor args.
if (newExpression.Constructor == null)
{
return false;
}

if (newExpression.Arguments.Count > 0
&& newExpression.Members == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,12 @@ private Expression SnapshotExpression(Expression selector)

case NewExpression newExpression:
{
// For .NET Framework only. If ctor is null that means the type is struct and has no ctor args.
if (newExpression.Constructor == null)
{
return Expression.Default(newExpression.Type);
}

var arguments = new Expression[newExpression.Arguments.Count];
for (var i = 0; i < newExpression.Arguments.Count; i++)
{
Expand Down