-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
4,054 additions
and
261 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
134 changes: 67 additions & 67 deletions
134
...ressionTranslators/RowNumberTranslator.cs → ...lators/RelationalDbFunctionsTranslator.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 |
---|---|---|
@@ -1,67 +1,67 @@ | ||
using System.Reflection; | ||
using Microsoft.EntityFrameworkCore.Diagnostics; | ||
using Microsoft.EntityFrameworkCore.Query; | ||
using Microsoft.EntityFrameworkCore.Query.SqlExpressions; | ||
using Microsoft.EntityFrameworkCore.Storage; | ||
using Thinktecture.EntityFrameworkCore.Query.SqlExpressions; | ||
|
||
namespace Thinktecture.EntityFrameworkCore.Query.ExpressionTranslators; | ||
|
||
/// <summary> | ||
/// Translated extension method "RowNumber" | ||
/// </summary> | ||
public sealed class RowNumberTranslator : IMethodCallTranslator | ||
{ | ||
private readonly ISqlExpressionFactory _sqlExpressionFactory; | ||
|
||
internal RowNumberTranslator(ISqlExpressionFactory sqlExpressionFactory) | ||
{ | ||
_sqlExpressionFactory = sqlExpressionFactory; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public SqlExpression? Translate( | ||
SqlExpression? instance, | ||
MethodInfo method, | ||
IReadOnlyList<SqlExpression> arguments, | ||
IDiagnosticsLogger<DbLoggerCategory.Query> logger) | ||
{ | ||
ArgumentNullException.ThrowIfNull(method); | ||
ArgumentNullException.ThrowIfNull(arguments); | ||
|
||
if (method.DeclaringType != typeof(RelationalDbFunctionsExtensions)) | ||
return null; | ||
|
||
switch (method.Name) | ||
{ | ||
case nameof(RelationalDbFunctionsExtensions.OrderBy): | ||
{ | ||
var orderBy = arguments.Skip(1).Select(e => new OrderingExpression(_sqlExpressionFactory.ApplyDefaultTypeMapping(e), true)).ToList(); | ||
return new RowNumberClauseOrderingsExpression(orderBy); | ||
} | ||
case nameof(RelationalDbFunctionsExtensions.OrderByDescending): | ||
{ | ||
var orderBy = arguments.Skip(1).Select(e => new OrderingExpression(_sqlExpressionFactory.ApplyDefaultTypeMapping(e), false)).ToList(); | ||
return new RowNumberClauseOrderingsExpression(orderBy); | ||
} | ||
case nameof(RelationalDbFunctionsExtensions.ThenBy): | ||
{ | ||
var orderBy = arguments.Skip(1).Select(e => new OrderingExpression(_sqlExpressionFactory.ApplyDefaultTypeMapping(e), true)); | ||
return ((RowNumberClauseOrderingsExpression)arguments[0]).AddColumns(orderBy); | ||
} | ||
case nameof(RelationalDbFunctionsExtensions.ThenByDescending): | ||
{ | ||
var orderBy = arguments.Skip(1).Select(e => new OrderingExpression(_sqlExpressionFactory.ApplyDefaultTypeMapping(e), false)); | ||
return ((RowNumberClauseOrderingsExpression)arguments[0]).AddColumns(orderBy); | ||
} | ||
case nameof(RelationalDbFunctionsExtensions.RowNumber): | ||
{ | ||
var partitionBy = arguments.Skip(1).Take(arguments.Count - 2).Select(e => _sqlExpressionFactory.ApplyDefaultTypeMapping(e)).ToList(); | ||
var orderings = (RowNumberClauseOrderingsExpression)arguments[^1]; | ||
return new RowNumberExpression(partitionBy, orderings.Orderings, RelationalTypeMapping.NullMapping); | ||
} | ||
default: | ||
throw new InvalidOperationException($"Unexpected method '{method.Name}' in '{nameof(RelationalDbFunctionsExtensions)}'."); | ||
} | ||
} | ||
} | ||
using System.Reflection; | ||
using Microsoft.EntityFrameworkCore.Diagnostics; | ||
using Microsoft.EntityFrameworkCore.Query; | ||
using Microsoft.EntityFrameworkCore.Query.SqlExpressions; | ||
using Microsoft.EntityFrameworkCore.Storage; | ||
using Thinktecture.EntityFrameworkCore.Query.SqlExpressions; | ||
|
||
namespace Thinktecture.EntityFrameworkCore.Query.ExpressionTranslators; | ||
|
||
/// <summary> | ||
/// Translates extension methods like "RowNumber" | ||
/// </summary> | ||
public sealed class RelationalDbFunctionsTranslator : IMethodCallTranslator | ||
{ | ||
private readonly ISqlExpressionFactory _sqlExpressionFactory; | ||
|
||
internal RelationalDbFunctionsTranslator(ISqlExpressionFactory sqlExpressionFactory) | ||
{ | ||
_sqlExpressionFactory = sqlExpressionFactory; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public SqlExpression? Translate( | ||
SqlExpression? instance, | ||
MethodInfo method, | ||
IReadOnlyList<SqlExpression> arguments, | ||
IDiagnosticsLogger<DbLoggerCategory.Query> logger) | ||
{ | ||
ArgumentNullException.ThrowIfNull(method); | ||
ArgumentNullException.ThrowIfNull(arguments); | ||
|
||
if (method.DeclaringType != typeof(RelationalDbFunctionsExtensions)) | ||
return null; | ||
|
||
switch (method.Name) | ||
{ | ||
case nameof(RelationalDbFunctionsExtensions.OrderBy): | ||
{ | ||
var orderBy = arguments.Skip(1).Select(e => new OrderingExpression(_sqlExpressionFactory.ApplyDefaultTypeMapping(e), true)).ToList(); | ||
return new WindowFunctionOrderingsExpression(orderBy); | ||
} | ||
case nameof(RelationalDbFunctionsExtensions.OrderByDescending): | ||
{ | ||
var orderBy = arguments.Skip(1).Select(e => new OrderingExpression(_sqlExpressionFactory.ApplyDefaultTypeMapping(e), false)).ToList(); | ||
return new WindowFunctionOrderingsExpression(orderBy); | ||
} | ||
case nameof(RelationalDbFunctionsExtensions.ThenBy): | ||
{ | ||
var orderBy = arguments.Skip(1).Select(e => new OrderingExpression(_sqlExpressionFactory.ApplyDefaultTypeMapping(e), true)); | ||
return ((WindowFunctionOrderingsExpression)arguments[0]).AddColumns(orderBy); | ||
} | ||
case nameof(RelationalDbFunctionsExtensions.ThenByDescending): | ||
{ | ||
var orderBy = arguments.Skip(1).Select(e => new OrderingExpression(_sqlExpressionFactory.ApplyDefaultTypeMapping(e), false)); | ||
return ((WindowFunctionOrderingsExpression)arguments[0]).AddColumns(orderBy); | ||
} | ||
case nameof(RelationalDbFunctionsExtensions.RowNumber): | ||
{ | ||
var partitionBy = arguments.Skip(1).Take(arguments.Count - 2).Select(e => _sqlExpressionFactory.ApplyDefaultTypeMapping(e)).ToList(); | ||
var orderings = (WindowFunctionOrderingsExpression)arguments[^1]; | ||
return new RowNumberExpression(partitionBy, orderings.Orderings, RelationalTypeMapping.NullMapping); | ||
} | ||
default: | ||
throw new InvalidOperationException($"Unexpected method '{method.Name}' in '{nameof(RelationalDbFunctionsExtensions)}'."); | ||
} | ||
} | ||
} |
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.