Skip to content

Commit

Permalink
Query: Add null check in hash computation in SqlFunctionExpression
Browse files Browse the repository at this point in the history
Resolves #23336
  • Loading branch information
smitpatel committed Nov 16, 2020
1 parent d05f81d commit f8fcf5a
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,12 @@ public override int GetHashCode()
hash.Add(IsNiladic);
hash.Add(Schema);
hash.Add(Instance);
for (var i = 0; i < Arguments.Count; i++)
if (Arguments != null)
{
hash.Add(Arguments[i]);
for (var i = 0; i < Arguments.Count; i++)
{
hash.Add(Arguments[i]);
}
}

return hash.ToHashCode();
Expand Down
30 changes: 30 additions & 0 deletions test/EFCore.Specification.Tests/Query/SpatialQueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,36 @@ public virtual Task Z(bool async)
});
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task XY_with_collection_join(bool async)
{
return AssertFirstOrDefault(
async,
ss => ss.Set<PointEntity>()
.OrderBy(e => e.Id)
.Select(e => new
{
e.Id,
I = new
{
X = e.Point == null ? (double?)null : e.Point.X,
Y = e.Point == null ? (double?)null : e.Point.Y
},
List = ss.Set<PointEntity>().Where(i => i.Id == e.Id).ToList()
}),
asserter: (e, a) =>
{
AssertEqual(e.Id, a.Id);
AssertEqual(e.I, a.I);
AssertCollection(e.List, a.List, elementSorter: e=> e.Id, elementAsserter: (ei, ai) =>
{
Assert.Equal(ei.Geometry, ai.Geometry, GeometryComparer.Instance);
Assert.Equal(ei.Point, ai.Point, GeometryComparer.Instance);
});
});
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task IsEmpty_equal_to_null(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,21 @@ public override async Task Z(bool async)
FROM [PointEntity] AS [p]");
}

public override async Task XY_with_collection_join(bool async)
{
await base.XY_with_collection_join(async);

AssertSql(
@"SELECT [t].[Id], [t].[c], [t].[c0], [p0].[Id], [p0].[Geometry], [p0].[Point], [p0].[PointM], [p0].[PointZ], [p0].[PointZM]
FROM (
SELECT TOP(1) [p].[Id], [p].[Point].Long AS [c], [p].[Point].Lat AS [c0]
FROM [PointEntity] AS [p]
ORDER BY [p].[Id]
) AS [t]
LEFT JOIN [PointEntity] AS [p0] ON [t].[Id] = [p0].[Id]
ORDER BY [t].[Id], [p0].[Id]");
}

public override async Task IsEmpty_equal_to_null(bool async)
{
await base.IsEmpty_equal_to_null(async);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,21 @@ public override async Task Z(bool async)
FROM [PointEntity] AS [p]");
}

public override async Task XY_with_collection_join(bool async)
{
await base.XY_with_collection_join(async);

AssertSql(
@"SELECT [t].[Id], [t].[c], [t].[c0], [p0].[Id], [p0].[Geometry], [p0].[Point], [p0].[PointM], [p0].[PointZ], [p0].[PointZM]
FROM (
SELECT TOP(1) [p].[Id], [p].[Point].STX AS [c], [p].[Point].STY AS [c0]
FROM [PointEntity] AS [p]
ORDER BY [p].[Id]
) AS [t]
LEFT JOIN [PointEntity] AS [p0] ON [t].[Id] = [p0].[Id]
ORDER BY [t].[Id], [p0].[Id]");
}

public override async Task IsEmpty_equal_to_null(bool async)
{
await base.IsEmpty_equal_to_null(async);
Expand Down

0 comments on commit f8fcf5a

Please sign in to comment.