-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for nested navigations in filters
Part of #12086
- Loading branch information
1 parent
a2ce460
commit 84860c8
Showing
14 changed files
with
302 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/EFCore.Cosmos/Query/Pipeline/ObjectAccessExpression.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Linq.Expressions; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Query.Internal; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Pipeline | ||
{ | ||
public class ObjectAccessExpression : SqlExpression | ||
{ | ||
private readonly Expression _outerExpression; | ||
|
||
public ObjectAccessExpression(INavigation navigation, Expression outerExpression) | ||
: base(navigation.ClrType, null) | ||
{ | ||
Name = navigation.GetTargetType().GetCosmosContainingPropertyName(); | ||
if (Name == null) | ||
{ | ||
throw new InvalidOperationException( | ||
$"Navigation '{navigation.DeclaringEntityType.DisplayName()}.{navigation.Name}' doesn't point to a nested entity."); | ||
} | ||
|
||
Navigation = navigation; | ||
_outerExpression = outerExpression; | ||
} | ||
|
||
public string Name { get; } | ||
|
||
public INavigation Navigation { get; } | ||
|
||
protected override Expression VisitChildren(ExpressionVisitor visitor) | ||
{ | ||
var outerExpression = visitor.Visit(_outerExpression); | ||
|
||
return Update(outerExpression); | ||
} | ||
|
||
public ObjectAccessExpression Update(Expression outerExpression) | ||
=> outerExpression != _outerExpression | ||
? new ObjectAccessExpression(Navigation, outerExpression) | ||
: this; | ||
|
||
public override void Print(ExpressionPrinter expressionPrinter) => expressionPrinter.StringBuilder.Append(ToString()); | ||
|
||
public override string ToString() => $"{_outerExpression}[\"{Name}\"]"; | ||
|
||
public override bool Equals(object obj) | ||
=> obj != null | ||
&& (ReferenceEquals(this, obj) | ||
|| obj is ObjectAccessExpression objectAccessExpression | ||
&& Equals(objectAccessExpression)); | ||
|
||
private bool Equals(ObjectAccessExpression objectAccessExpression) | ||
=> base.Equals(objectAccessExpression) | ||
&& string.Equals(Name, objectAccessExpression.Name) | ||
&& _outerExpression.Equals(objectAccessExpression._outerExpression); | ||
|
||
public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), Name, _outerExpression); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.