Skip to content

Commit 561d82e

Browse files
committed
wip
1 parent 354adda commit 561d82e

12 files changed

+98
-81
lines changed

src/EFCore.Relational/Infrastructure/EntityFrameworkRelationalServicesBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ public override EntityFrameworkServicesBuilder TryAddCoreServices()
234234
.AddDependencyScoped<RelationalQueryContextDependencies>()
235235
.AddDependencyScoped<RelationalQueryCompilationContextDependencies>()
236236
.AddDependencyScoped<RelationalAdHocMapperDependencies>()
237-
.AddDependencyScoped<WindowBuilderExpressionFactory>();
237+
.AddDependencyScoped<WindowBuilderExpressionFactory>()
238+
.AddDependencyScoped<RelationalWindowAggregateMethodTranslatorDependencies>();
238239

239240
return base.TryAddCoreServices();
240241
}

src/EFCore.Relational/Query/WindowBuilderExpressionFactory.cs renamed to src/EFCore.Relational/Query/Internal/WindowBuilderExpressionFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using System.Text;
88
using System.Threading.Tasks;
99

10-
namespace Microsoft.EntityFrameworkCore.Query;
10+
namespace Microsoft.EntityFrameworkCore.Query.Internal;
1111

1212
/// <summary>
1313
/// todo

src/EFCore.Relational/Query/RelationalWindowAggregateMethodTranslator.cs

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,25 @@ namespace Microsoft.EntityFrameworkCore.Query;
1818
/// </summary>
1919
public class RelationalWindowAggregateMethodTranslator : IWindowAggregateMethodCallTranslator
2020
{
21-
private readonly ISqlExpressionFactory _sqlExpressionFactory;
21+
/// <summary>
22+
/// todo
23+
/// </summary>
24+
public virtual ISqlExpressionFactory SqlExpressionFactory => Dependencies.SqlExpressionFactory;
25+
26+
/// <summary>
27+
/// todo
28+
/// </summary>
29+
public virtual RelationalWindowAggregateMethodTranslatorDependencies Dependencies { get; }
2230

2331
/// <summary>
2432
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
2533
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
2634
/// any release. You should only use it directly in your code with extreme caution and knowing that
2735
/// doing so can result in application failures when updating to a new Entity Framework Core release.
2836
/// </summary>
29-
public RelationalWindowAggregateMethodTranslator(ISqlExpressionFactory sqlExpressionFactory)
37+
public RelationalWindowAggregateMethodTranslator(RelationalWindowAggregateMethodTranslatorDependencies dependencies)
3038
{
31-
_sqlExpressionFactory = sqlExpressionFactory;
39+
Dependencies = dependencies;
3240
}
3341

3442
/// <summary>
@@ -50,118 +58,118 @@ public RelationalWindowAggregateMethodTranslator(ISqlExpressionFactory sqlExpres
5058
case nameof(RelationalWindowAggregateFunctionExtensions.Average)
5159
when methodInfo == RelationalWindowAggregateMethods.Average:
5260

53-
return _sqlExpressionFactory.Function("AVG", arguments, false, [false], arguments[0].Type, arguments[0].TypeMapping);
61+
return SqlExpressionFactory.Function("AVG", arguments, false, [false], arguments[0].Type, arguments[0].TypeMapping);
5462

5563
case nameof(RelationalWindowAggregateFunctionExtensions.Average)
5664
when methodInfo == RelationalWindowAggregateMethods.AverageFilter:
5765

58-
return _sqlExpressionFactory.Function("AVG", BuildCaseExpression(arguments), true, [false], arguments[0].Type, arguments[0].TypeMapping);
66+
return SqlExpressionFactory.Function("AVG", BuildCaseExpression(arguments), true, [false], arguments[0].Type, arguments[0].TypeMapping);
5967

6068
case nameof(RelationalWindowAggregateFunctionExtensions.Count)
6169
when methodInfo == RelationalWindowAggregateMethods.CountAll:
6270

63-
return _sqlExpressionFactory.Function("COUNT", [_sqlExpressionFactory.Fragment("*")], false, [false], typeof(int));
71+
return SqlExpressionFactory.Function("COUNT", [SqlExpressionFactory.Fragment("*")], false, [false], typeof(int));
6472

6573
case nameof(RelationalWindowAggregateFunctionExtensions.Count)
6674
when methodInfo == RelationalWindowAggregateMethods.CountAllFilter:
6775

68-
return _sqlExpressionFactory.Function("COUNT", BuildCaseExpression(arguments, _sqlExpressionFactory.Constant("1")), true, [false], typeof(int));
76+
return SqlExpressionFactory.Function("COUNT", BuildCaseExpression(arguments, SqlExpressionFactory.Constant("1")), true, [false], typeof(int));
6977

7078
case nameof(RelationalWindowAggregateFunctionExtensions.Count)
7179
when methodInfo == RelationalWindowAggregateMethods.CountCol:
7280

73-
return _sqlExpressionFactory.Function("COUNT", arguments, false, [false], typeof(int));
81+
return SqlExpressionFactory.Function("COUNT", arguments, false, [false], typeof(int));
7482

7583
case nameof(RelationalWindowAggregateFunctionExtensions.Count)
7684
when methodInfo == RelationalWindowAggregateMethods.CountColFilter:
7785

78-
return _sqlExpressionFactory.Function("COUNT", BuildCaseExpression(arguments), true, [false], typeof(int));
86+
return SqlExpressionFactory.Function("COUNT", BuildCaseExpression(arguments), true, [false], typeof(int));
7987

8088
case nameof(RelationalWindowAggregateFunctionExtensions.CumeDist)
8189
when methodInfo == RelationalWindowAggregateMethods.CumeDist:
8290

83-
return _sqlExpressionFactory.Function("CUME_DIST", Enumerable.Empty<SqlExpression>(), false, [], typeof(double));
91+
return SqlExpressionFactory.Function("CUME_DIST", Enumerable.Empty<SqlExpression>(), false, [], typeof(double));
8492

8593
case nameof(RelationalWindowAggregateFunctionExtensions.DenseRank)
8694
when methodInfo == RelationalWindowAggregateMethods.DenseRank:
8795

88-
return _sqlExpressionFactory.Function("DENSE_RANK", Enumerable.Empty<SqlExpression>(), false, [], typeof(long));
96+
return SqlExpressionFactory.Function("DENSE_RANK", Enumerable.Empty<SqlExpression>(), false, [], typeof(long));
8997

9098
case nameof(RelationalWindowAggregateFunctionExtensions.FirstValue)
9199
when methodInfo == RelationalWindowAggregateMethods.FirstValueFrameResults:
92100

93101
case nameof(RelationalWindowAggregateFunctionExtensions.FirstValue)
94102
when methodInfo == RelationalWindowAggregateMethods.FirstValueOrderThen:
95103

96-
return _sqlExpressionFactory.Function("FIRST_VALUE", arguments, true, [false], arguments[0].Type, arguments[0].TypeMapping);
104+
return SqlExpressionFactory.Function("FIRST_VALUE", arguments, true, [false], arguments[0].Type, arguments[0].TypeMapping);
97105

98106
case nameof(RelationalWindowAggregateFunctionExtensions.Lag)
99107
when methodInfo == RelationalWindowAggregateMethods.Lag:
100108

101-
return _sqlExpressionFactory.Function("LAG", arguments, true, [false, false, false], arguments[0].Type, arguments[0].TypeMapping);
109+
return SqlExpressionFactory.Function("LAG", arguments, true, [false, false, false], arguments[0].Type, arguments[0].TypeMapping);
102110

103111
case nameof(RelationalWindowAggregateFunctionExtensions.LastValue)
104112
when methodInfo == RelationalWindowAggregateMethods.LastValueOrderThen:
105113

106114
case nameof(RelationalWindowAggregateFunctionExtensions.LastValue)
107115
when methodInfo == RelationalWindowAggregateMethods.LastValueFrameResults:
108116

109-
return _sqlExpressionFactory.Function("LAST_VALUE", arguments, true, [false], arguments[0].Type, arguments[0].TypeMapping);
117+
return SqlExpressionFactory.Function("LAST_VALUE", arguments, true, [false], arguments[0].Type, arguments[0].TypeMapping);
110118

111119
case nameof(RelationalWindowAggregateFunctionExtensions.Lead)
112120
when methodInfo == RelationalWindowAggregateMethods.Lead:
113121

114-
return _sqlExpressionFactory.Function("LEAD", arguments, true, [false, false, false], arguments[0].Type, arguments[0].TypeMapping);
122+
return SqlExpressionFactory.Function("LEAD", arguments, true, [false, false, false], arguments[0].Type, arguments[0].TypeMapping);
115123

116124
case nameof(RelationalWindowAggregateFunctionExtensions.Max)
117125
when methodInfo == RelationalWindowAggregateMethods.Max:
118126

119-
return _sqlExpressionFactory.Function("MAX", arguments, false, [false], arguments[0].Type, arguments[0].TypeMapping);
127+
return SqlExpressionFactory.Function("MAX", arguments, false, [false], arguments[0].Type, arguments[0].TypeMapping);
120128

121129
case nameof(RelationalWindowAggregateFunctionExtensions.Max)
122130
when methodInfo == RelationalWindowAggregateMethods.MaxFilter:
123131

124-
return _sqlExpressionFactory.Function("MAX", BuildCaseExpression(arguments), true, [false], arguments[0].Type, arguments[0].TypeMapping);
132+
return SqlExpressionFactory.Function("MAX", BuildCaseExpression(arguments), true, [false], arguments[0].Type, arguments[0].TypeMapping);
125133

126134
case nameof(RelationalWindowAggregateFunctionExtensions.Min)
127135
when methodInfo == RelationalWindowAggregateMethods.Min:
128136

129-
return _sqlExpressionFactory.Function("MIN", arguments, false, [false], arguments[0].Type, arguments[0].TypeMapping);
137+
return SqlExpressionFactory.Function("MIN", arguments, false, [false], arguments[0].Type, arguments[0].TypeMapping);
130138

131139
case nameof(RelationalWindowAggregateFunctionExtensions.Min)
132140
when methodInfo == RelationalWindowAggregateMethods.MinFilter:
133141

134-
return _sqlExpressionFactory.Function("MIN", BuildCaseExpression(arguments), true, [false], arguments[0].Type, arguments[0].TypeMapping);
142+
return SqlExpressionFactory.Function("MIN", BuildCaseExpression(arguments), true, [false], arguments[0].Type, arguments[0].TypeMapping);
135143

136144
case nameof(RelationalWindowAggregateFunctionExtensions.NTile)
137145
when methodInfo == RelationalWindowAggregateMethods.NTile:
138146

139-
return _sqlExpressionFactory.Function("NTILE", arguments, false, [false], typeof(long));
147+
return SqlExpressionFactory.Function("NTILE", arguments, false, [false], typeof(long));
140148

141149
case nameof(RelationalWindowAggregateFunctionExtensions.PercentRank)
142150
when methodInfo == RelationalWindowAggregateMethods.PercentRank:
143151

144-
return _sqlExpressionFactory.Function("PERCENT_RANK", Enumerable.Empty<SqlExpression>(), false, [], typeof(double));
152+
return SqlExpressionFactory.Function("PERCENT_RANK", Enumerable.Empty<SqlExpression>(), false, [], typeof(double));
145153

146154
case nameof(RelationalWindowAggregateFunctionExtensions.Rank)
147155
when methodInfo == RelationalWindowAggregateMethods.Rank:
148156

149-
return _sqlExpressionFactory.Function("RANK", Enumerable.Empty<SqlExpression>(), false, [], typeof(long));
157+
return SqlExpressionFactory.Function("RANK", Enumerable.Empty<SqlExpression>(), false, [], typeof(long));
150158

151159
case nameof(RelationalWindowAggregateFunctionExtensions.RowNumber)
152160
when methodInfo == RelationalWindowAggregateMethods.RowNumber:
153161

154-
return _sqlExpressionFactory.Function("ROW_NUMBER", Enumerable.Empty<SqlExpression>(), false, [], typeof(long));
162+
return SqlExpressionFactory.Function("ROW_NUMBER", Enumerable.Empty<SqlExpression>(), false, [], typeof(long));
155163

156164
case nameof(RelationalWindowAggregateFunctionExtensions.Sum)
157165
when methodInfo == RelationalWindowAggregateMethods.Sum:
158166

159-
return _sqlExpressionFactory.Function("SUM", arguments, false, [false], arguments[0].Type, arguments[0].TypeMapping);
167+
return SqlExpressionFactory.Function("SUM", arguments, false, [false], arguments[0].Type, arguments[0].TypeMapping);
160168

161169
case nameof(RelationalWindowAggregateFunctionExtensions.Sum)
162170
when methodInfo == RelationalWindowAggregateMethods.SumFilter:
163171

164-
return _sqlExpressionFactory.Function("SUM", BuildCaseExpression(arguments), true, [false], arguments[0].Type, arguments[0].TypeMapping);
172+
return SqlExpressionFactory.Function("SUM", BuildCaseExpression(arguments), true, [false], arguments[0].Type, arguments[0].TypeMapping);
165173
}
166174

167175
return null;
@@ -174,7 +182,7 @@ public RelationalWindowAggregateMethodTranslator(ISqlExpressionFactory sqlExpres
174182
/// <param name="arguments">todo</param>
175183
/// <returns>todo</returns>
176184
protected virtual SqlExpression[] BuildCaseExpression(IReadOnlyList<SqlExpression> arguments, SqlExpression? result = null)
177-
=> [_sqlExpressionFactory.Case([new CaseWhenClause(ProcessCaseWhen(arguments[result == null ? 1 : 0]), result ?? arguments[0])], _sqlExpressionFactory.Constant(null, typeof(object)))] ;
185+
=> [SqlExpressionFactory.Case([new CaseWhenClause(ProcessCaseWhen(arguments[result == null ? 1 : 0]), result ?? arguments[0])], SqlExpressionFactory.Constant(null, typeof(object)))];
178186

179187

180188
/// <summary>
@@ -184,11 +192,11 @@ protected virtual SqlExpression[] BuildCaseExpression(IReadOnlyList<SqlExpressio
184192
/// <returns>todo</returns>
185193
protected virtual SqlExpression ProcessCaseWhen(SqlExpression whenExpression)
186194
{
187-
if(whenExpression is SqlBinaryExpression { Left : InExpression inExpression, Right : SqlConstantExpression constantExpression })
195+
if (whenExpression is SqlBinaryExpression { Left: InExpression inExpression, Right: SqlConstantExpression constantExpression })
188196
{
189197
return constantExpression.Value as bool? == true
190198
? inExpression
191-
: _sqlExpressionFactory.Not(inExpression);
199+
: SqlExpressionFactory.Not(inExpression);
192200
}
193201

194202
return whenExpression;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace Microsoft.EntityFrameworkCore.Query
11+
{
12+
/// <summary>
13+
/// todo
14+
/// </summary>
15+
public record RelationalWindowAggregateMethodTranslatorDependencies
16+
{
17+
/// <summary>
18+
/// todo
19+
/// </summary>
20+
/// <param name="sqlExpressionFactory">todo</param>
21+
public RelationalWindowAggregateMethodTranslatorDependencies(ISqlExpressionFactory sqlExpressionFactory)
22+
{
23+
SqlExpressionFactory = sqlExpressionFactory;
24+
}
25+
26+
/// <summary>
27+
/// todo
28+
/// </summary>
29+
public virtual ISqlExpressionFactory SqlExpressionFactory { get; }
30+
}
31+
}

src/EFCore.Relational/Query/RelationalWindowBuilderExpressionFactory.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,22 @@ public RelationalWindowBuilderExpression(ISqlExpressionFactory sqlExpressionFact
3535
/// <summary>
3636
/// todo
3737
/// </summary>
38-
public IReadOnlyList<OrderingExpression> OrderingExpressions => _orderingExpressions;
38+
public virtual IReadOnlyList<OrderingExpression> OrderingExpressions => _orderingExpressions;
3939

4040
/// <summary>
4141
/// todo
4242
/// </summary>
43-
public WindowPartitionExpression? PartitionExpression => _partitionExpression;
43+
public virtual WindowPartitionExpression? PartitionExpression => _partitionExpression;
4444

4545
/// <summary>
4646
/// todo
4747
/// </summary>
48-
public WindowFrameExpression? FrameExpression => _frameExpression;
48+
public virtual WindowFrameExpression? FrameExpression => _frameExpression;
4949

5050
/// <summary>
5151
/// todo
5252
/// </summary>
53-
public SqlConstantExpression? ExcludeExpression => _excludeExpression;
53+
public virtual SqlConstantExpression? ExcludeExpression => _excludeExpression;
5454

5555
/// <summary>
5656
/// todo

src/EFCore.Relational/Query/SqlExpressions/WindowFrameExpression.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ public abstract class WindowFrameExpression : Expression, IPrintableExpression
1717
/// <summary>
1818
/// todo
1919
/// </summary>
20-
public SqlExpression? Preceding { get; init; }
20+
public virtual SqlExpression? Preceding { get; init; }
2121

2222
/// <summary>
2323
/// todo
2424
/// </summary>
25-
public SqlExpression? Following { get; init; }
25+
public virtual SqlExpression? Following { get; init; }
2626

2727
/// <summary>
2828
/// todo - bettter name
@@ -32,7 +32,7 @@ public abstract class WindowFrameExpression : Expression, IPrintableExpression
3232
/// <summary>
3333
/// todo
3434
/// </summary>
35-
public SqlExpression? Exclude { get; set; }
35+
public virtual SqlExpression? Exclude { get; set; }
3636

3737
/// <summary>
3838
/// todo

src/EFCore.Relational/Query/SqlExpressions/WindowOverExpression.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@ public class WindowOverExpression : SqlExpression, IPrintableExpression
2020
/// <summary>
2121
/// todo
2222
/// </summary>
23-
public WindowPartitionExpression? Partition { get; init; }
23+
public virtual WindowPartitionExpression? Partition { get; init; }
2424

2525
/// <summary>
2626
/// todo
2727
/// </summary>
28-
public SqlFunctionExpression Aggregate { get; set; }
28+
public virtual SqlFunctionExpression Aggregate { get; set; }
2929

3030
/// <summary>
3131
/// todo
3232
/// </summary>
33-
public IReadOnlyList<OrderingExpression> Ordering { get; init; }
33+
public virtual IReadOnlyList<OrderingExpression> Ordering { get; init; }
3434

3535
/// <summary>
3636
/// todo
3737
/// </summary>
38-
public WindowFrameExpression? WindowFrame { get; init; }
38+
public virtual WindowFrameExpression? WindowFrame { get; init; }
3939

4040
/// <summary>
4141
/// todo
4242
/// </summary>
43-
public SqlExpression? Filter { get; init; }
43+
public virtual SqlExpression? Filter { get; init; }
4444

4545

4646
/// <summary>

src/EFCore.Relational/Query/SqlExpressions/WindowPartitionExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class WindowPartitionExpression : Expression, IPrintableExpression
1818
/// <summary>
1919
/// todo
2020
/// </summary>
21-
public IReadOnlyList<SqlExpression> Partitions { get; init; }
21+
public virtual IReadOnlyList<SqlExpression> Partitions { get; init; }
2222

2323
/// <summary>
2424
/// tests

src/EFCore.SqlServer/Extensions/SqlServerServiceCollectionExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ public static IServiceCollection AddEntityFrameworkSqlServer(this IServiceCollec
118118
.TryAdd<IQueryCompilationContextFactory, SqlServerQueryCompilationContextFactory>()
119119
.TryAdd<IMethodCallTranslatorProvider, SqlServerMethodCallTranslatorProvider>()
120120
.TryAdd<IAggregateMethodCallTranslatorProvider, SqlServerAggregateMethodCallTranslatorProvider>()
121-
//.TryAdd<IWindowAggregateMethodCallTranslatorProvider, SqlServerWindowAggregateMethodCallTranslatorProvider>()
122121
.TryAdd<IWindowAggregateMethodCallTranslator, SqlServerWindowAggregateMethodTranslator>()
123122
.TryAdd<IMemberTranslatorProvider, SqlServerMemberTranslatorProvider>()
124123
.TryAdd<IQuerySqlGeneratorFactory, SqlServerQuerySqlGeneratorFactory>()

0 commit comments

Comments
 (0)