@@ -18,58 +18,118 @@ namespace Microsoft.EntityFrameworkCore;
18
18
/// </remarks>
19
19
public static class CosmosQueryableExtensions
20
20
{
21
- internal static readonly MethodInfo WithPartitionKeyMethodInfo
21
+ internal static readonly MethodInfo WithPartitionKeyMethodInfo1
22
+ = typeof ( CosmosQueryableExtensions ) . GetTypeInfo ( )
23
+ . GetDeclaredMethods ( nameof ( WithPartitionKey ) )
24
+ . Single ( mi => mi . GetParameters ( ) . Length == 2 ) ;
25
+
26
+ internal static readonly MethodInfo WithPartitionKeyMethodInfo2
22
27
= typeof ( CosmosQueryableExtensions ) . GetTypeInfo ( )
23
28
. GetDeclaredMethods ( nameof ( WithPartitionKey ) )
24
29
. Single ( mi => mi . GetParameters ( ) . Length == 3 ) ;
25
30
31
+ internal static readonly MethodInfo WithPartitionKeyMethodInfo3
32
+ = typeof ( CosmosQueryableExtensions ) . GetTypeInfo ( )
33
+ . GetDeclaredMethods ( nameof ( WithPartitionKey ) )
34
+ . Single ( mi => mi . GetParameters ( ) . Length == 4 ) ;
35
+
26
36
/// <summary>
27
- /// Specify the partition key value for partition used for the query. Required when using
28
- /// a resource token that provides permission based on a partition key for authentication.
37
+ /// Specify the partition key for partition used for the query.
38
+ /// Required when using a resource token that provides permission based on a partition key for authentication,
29
39
/// </summary>
30
40
/// <remarks>
31
41
/// See <see href="https://aka.ms/efcore-docs-query">Querying data with EF Core</see>, and
32
42
/// <see href="https://aka.ms/efcore-docs-cosmos">Accessing Azure Cosmos DB with EF Core</see> for more information and examples.
33
43
/// </remarks>
34
44
/// <typeparam name="TEntity">The type of entity being queried.</typeparam>
35
45
/// <param name="source">The source query.</param>
36
- /// <param name="partitionKey ">The partition key value.</param>
46
+ /// <param name="partitionKeyValue ">The partition key value.</param>
37
47
/// <returns>A new query with the set partition key.</returns>
38
- public static IQueryable < TEntity > WithPartitionKey < TEntity > ( this IQueryable < TEntity > source , string partitionKey )
48
+ public static IQueryable < TEntity > WithPartitionKey < TEntity > ( this IQueryable < TEntity > source , object partitionKeyValue )
39
49
where TEntity : class
40
- => WithPartitionKey ( source , partitionKey , [ ] ) ;
50
+ {
51
+ Check . NotNull ( partitionKeyValue , nameof ( partitionKeyValue ) ) ;
52
+
53
+ return
54
+ source . Provider is EntityQueryProvider
55
+ ? source . Provider . CreateQuery < TEntity > (
56
+ Expression . Call (
57
+ instance : null ,
58
+ method : WithPartitionKeyMethodInfo1 . MakeGenericMethod ( typeof ( TEntity ) ) ,
59
+ source . Expression ,
60
+ Expression . Constant ( partitionKeyValue , typeof ( object ) ) ) )
61
+ : source ;
62
+ }
41
63
42
64
/// <summary>
43
- /// Specify the partition key for partition used for the query. Required when using
44
- /// a resource token that provides permission based on a partition key for authentication,
65
+ /// Specify the partition key for partition used for the query.
66
+ /// Required when using a resource token that provides permission based on a partition key for authentication,
45
67
/// </summary>
46
68
/// <remarks>
47
69
/// See <see href="https://aka.ms/efcore-docs-query">Querying data with EF Core</see>, and
48
70
/// <see href="https://aka.ms/efcore-docs-cosmos">Accessing Azure Cosmos DB with EF Core</see> for more information and examples.
49
71
/// </remarks>
50
72
/// <typeparam name="TEntity">The type of entity being queried.</typeparam>
51
73
/// <param name="source">The source query.</param>
52
- /// <param name="partitionKeyValue ">The partition key value .</param>
53
- /// <param name="additionalPartitionKeyValues">Additional values for hierarchical partitions .</param>
74
+ /// <param name="partitionKeyValue1 ">The first value in a hierarchical partition key.</param>
75
+ /// <param name="partitionKeyValue2">The second value in a hierarchical partition key .</param>
54
76
/// <returns>A new query with the set partition key.</returns>
55
77
public static IQueryable < TEntity > WithPartitionKey < TEntity > (
56
78
this IQueryable < TEntity > source ,
57
- object partitionKeyValue ,
58
- params object [ ] additionalPartitionKeyValues )
79
+ object partitionKeyValue1 ,
80
+ object partitionKeyValue2 )
59
81
where TEntity : class
60
82
{
61
- Check . NotNull ( partitionKeyValue , nameof ( partitionKeyValue ) ) ;
62
- Check . HasNoNulls ( additionalPartitionKeyValues , nameof ( additionalPartitionKeyValues ) ) ;
83
+ Check . NotNull ( partitionKeyValue1 , nameof ( partitionKeyValue1 ) ) ;
84
+ Check . NotNull ( partitionKeyValue2 , nameof ( partitionKeyValue2 ) ) ;
85
+
86
+ return
87
+ source . Provider is EntityQueryProvider
88
+ ? source . Provider . CreateQuery < TEntity > (
89
+ Expression . Call (
90
+ instance : null ,
91
+ method : WithPartitionKeyMethodInfo2 . MakeGenericMethod ( typeof ( TEntity ) ) ,
92
+ source . Expression ,
93
+ Expression . Constant ( partitionKeyValue1 , typeof ( object ) ) ,
94
+ Expression . Constant ( partitionKeyValue2 , typeof ( object ) ) ) )
95
+ : source ;
96
+ }
97
+
98
+ /// <summary>
99
+ /// Specify the partition key for partition used for the query.
100
+ /// Required when using a resource token that provides permission based on a partition key for authentication,
101
+ /// </summary>
102
+ /// <remarks>
103
+ /// See <see href="https://aka.ms/efcore-docs-query">Querying data with EF Core</see>, and
104
+ /// <see href="https://aka.ms/efcore-docs-cosmos">Accessing Azure Cosmos DB with EF Core</see> for more information and examples.
105
+ /// </remarks>
106
+ /// <typeparam name="TEntity">The type of entity being queried.</typeparam>
107
+ /// <param name="source">The source query.</param>
108
+ /// <param name="partitionKeyValue1">The first value in a hierarchical partition key.</param>
109
+ /// <param name="partitionKeyValue2">The second value in a hierarchical partition key.</param>
110
+ /// <param name="partitionKeyValue3">The third value in a hierarchical partition key.</param>
111
+ /// <returns>A new query with the set partition key.</returns>
112
+ public static IQueryable < TEntity > WithPartitionKey < TEntity > (
113
+ this IQueryable < TEntity > source ,
114
+ object partitionKeyValue1 ,
115
+ object partitionKeyValue2 ,
116
+ object partitionKeyValue3 )
117
+ where TEntity : class
118
+ {
119
+ Check . NotNull ( partitionKeyValue1 , nameof ( partitionKeyValue1 ) ) ;
120
+ Check . NotNull ( partitionKeyValue2 , nameof ( partitionKeyValue2 ) ) ;
121
+ Check . NotNull ( partitionKeyValue3 , nameof ( partitionKeyValue3 ) ) ;
63
122
64
123
return
65
124
source . Provider is EntityQueryProvider
66
125
? source . Provider . CreateQuery < TEntity > (
67
126
Expression . Call (
68
127
instance : null ,
69
- method : WithPartitionKeyMethodInfo . MakeGenericMethod ( typeof ( TEntity ) ) ,
128
+ method : WithPartitionKeyMethodInfo3 . MakeGenericMethod ( typeof ( TEntity ) ) ,
70
129
source . Expression ,
71
- Expression . Constant ( partitionKeyValue , typeof ( object ) ) ,
72
- Expression . Constant ( additionalPartitionKeyValues , typeof ( object [ ] ) ) ) )
130
+ Expression . Constant ( partitionKeyValue1 , typeof ( object ) ) ,
131
+ Expression . Constant ( partitionKeyValue2 , typeof ( object ) ) ,
132
+ Expression . Constant ( partitionKeyValue3 , typeof ( object ) ) ) )
73
133
: source ;
74
134
}
75
135
0 commit comments