-
Notifications
You must be signed in to change notification settings - Fork 225
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
7 changed files
with
228 additions
and
24 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
62 changes: 62 additions & 0 deletions
62
src/EFCore.PG/Query/Internal/NpgsqlQueryableMethodTranslatingExpressionVisitor.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 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Internal; | ||
|
||
public class NpgsqlQueryableMethodTranslatingExpressionVisitor : RelationalQueryableMethodTranslatingExpressionVisitor | ||
{ | ||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public NpgsqlQueryableMethodTranslatingExpressionVisitor( | ||
QueryableMethodTranslatingExpressionVisitorDependencies dependencies, | ||
RelationalQueryableMethodTranslatingExpressionVisitorDependencies relationalDependencies, | ||
QueryCompilationContext queryCompilationContext) | ||
: base(dependencies, relationalDependencies, queryCompilationContext) | ||
{ | ||
} | ||
|
||
protected override bool IsValidSelectExpressionForBulkDelete( | ||
SelectExpression selectExpression, | ||
EntityShaperExpression entityShaperExpression, | ||
[NotNullWhen(true)] out TableExpression? tableExpression) | ||
{ | ||
// The default relational behavior is to allow only single-table expressions, and the only permitted feature is a predicate. | ||
// Here we extend this to also inner joins to tables, which we generate via the PostgreSQL-specific USING construct. | ||
if (selectExpression.Offset == null | ||
&& selectExpression.Limit == null | ||
&& (!selectExpression.IsDistinct || entityShaperExpression.EntityType.FindPrimaryKey() != null) | ||
&& selectExpression.GroupBy.Count == 0 | ||
&& selectExpression.Having == null | ||
&& selectExpression.Orderings.Count == 0) | ||
{ | ||
TableExpressionBase? table = null; | ||
if (selectExpression.Tables.Count == 1) | ||
{ | ||
table = selectExpression.Tables[0]; | ||
} | ||
else if (selectExpression.Tables.All(t => t is TableExpression or InnerJoinExpression { Table: TableExpression })) | ||
{ | ||
var projectionBindingExpression = (ProjectionBindingExpression)entityShaperExpression.ValueBufferExpression; | ||
var entityProjectionExpression = (EntityProjectionExpression)selectExpression.GetProjection(projectionBindingExpression); | ||
var column = entityProjectionExpression.BindProperty(entityShaperExpression.EntityType.GetProperties().First()); | ||
table = column.Table; | ||
if (table is JoinExpressionBase joinExpressionBase) | ||
{ | ||
table = joinExpressionBase.Table; | ||
} | ||
} | ||
|
||
if (table is TableExpression te) | ||
{ | ||
tableExpression = te; | ||
return true; | ||
} | ||
} | ||
|
||
tableExpression = null; | ||
return false; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/EFCore.PG/Query/Internal/NpgsqlQueryableMethodTranslatingExpressionVisitorFactory.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,43 @@ | ||
namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Internal; | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public class NpgsqlQueryableMethodTranslatingExpressionVisitorFactory : IQueryableMethodTranslatingExpressionVisitorFactory | ||
{ | ||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public NpgsqlQueryableMethodTranslatingExpressionVisitorFactory( | ||
QueryableMethodTranslatingExpressionVisitorDependencies dependencies, | ||
RelationalQueryableMethodTranslatingExpressionVisitorDependencies relationalDependencies) | ||
{ | ||
Dependencies = dependencies; | ||
RelationalDependencies = relationalDependencies; | ||
} | ||
|
||
/// <summary> | ||
/// Dependencies for this service. | ||
/// </summary> | ||
protected virtual QueryableMethodTranslatingExpressionVisitorDependencies Dependencies { get; } | ||
|
||
/// <summary> | ||
/// Relational provider-specific dependencies for this service. | ||
/// </summary> | ||
protected virtual RelationalQueryableMethodTranslatingExpressionVisitorDependencies RelationalDependencies { get; } | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public virtual QueryableMethodTranslatingExpressionVisitor Create(QueryCompilationContext queryCompilationContext) | ||
=> new NpgsqlQueryableMethodTranslatingExpressionVisitor(Dependencies, RelationalDependencies, queryCompilationContext); | ||
} |
19 changes: 19 additions & 0 deletions
19
test/EFCore.PG.FunctionalTests/BulkUpdates/FiltersInheritanceBulkUpdatesNpgsqlTest.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,19 @@ | ||
using Microsoft.EntityFrameworkCore.BulkUpdates; | ||
using Npgsql.EntityFrameworkCore.PostgreSQL.Query; | ||
|
||
namespace Npgsql.EntityFrameworkCore.PostgreSQL.BulkUpdates; | ||
|
||
public class FiltersInheritanceBulkUpdatesNpgsqlTest : FiltersInheritanceBulkUpdatesTestBase<FiltersInheritanceQueryNpgsqlFixture> | ||
{ | ||
public FiltersInheritanceBulkUpdatesNpgsqlTest(FiltersInheritanceQueryNpgsqlFixture fixture) | ||
: base(fixture) | ||
{ | ||
} | ||
|
||
[ConditionalFact] | ||
public virtual void Check_all_tests_overridden() | ||
=> TestHelpers.AssertAllMethodsOverridden(GetType()); | ||
|
||
private void AssertSql(params string[] expected) | ||
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected); | ||
} |
19 changes: 19 additions & 0 deletions
19
test/EFCore.PG.FunctionalTests/BulkUpdates/InheritanceBulkUpdatesNpgsqlTest.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,19 @@ | ||
using Microsoft.EntityFrameworkCore.BulkUpdates; | ||
using Npgsql.EntityFrameworkCore.PostgreSQL.Query; | ||
|
||
namespace Npgsql.EntityFrameworkCore.PostgreSQL.BulkUpdates; | ||
|
||
public class InheritanceBulkUpdatesNpgsqlTest : InheritanceBulkUpdatesTestBase<InheritanceQueryNpgsqlFixture> | ||
{ | ||
public InheritanceBulkUpdatesNpgsqlTest(InheritanceQueryNpgsqlFixture fixture) | ||
: base(fixture) | ||
{ | ||
} | ||
|
||
[ConditionalFact] | ||
public virtual void Check_all_tests_overridden() | ||
=> TestHelpers.AssertAllMethodsOverridden(GetType()); | ||
|
||
private void AssertSql(params string[] expected) | ||
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected); | ||
} |
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