Skip to content

Commit 1acb0eb

Browse files
authored
Merge pull request #215 from microting/copilot/fix-target-table-update-issue
Fix DELETE with self-referencing subquery tests for MySQL/MariaDB < 11.0
2 parents ced65d4 + b340298 commit 1acb0eb

File tree

2 files changed

+288
-22
lines changed

2 files changed

+288
-22
lines changed

test/EFCore.MySql.FunctionalTests/BulkUpdates/NonSharedModelBulkUpdatesMySqlTest.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.EntityFrameworkCore.TestUtilities;
55
using MySqlConnector;
66
using Pomelo.EntityFrameworkCore.MySql.FunctionalTests.TestUtilities;
7+
using Pomelo.EntityFrameworkCore.MySql.Tests;
78
using Xunit;
89

910
namespace Pomelo.EntityFrameworkCore.MySql.FunctionalTests.BulkUpdates;
@@ -53,9 +54,11 @@ public override async Task Delete_aggregate_root_when_table_sharing_with_non_own
5354

5455
public override async Task Delete_predicate_based_on_optional_navigation(bool async)
5556
{
56-
await base.Delete_predicate_based_on_optional_navigation(async);
57+
if (AppConfig.ServerVersion.Supports.DeleteWithSelfReferencingSubquery)
58+
{
59+
await base.Delete_predicate_based_on_optional_navigation(async);
5760

58-
AssertSql(
61+
AssertSql(
5962
"""
6063
DELETE `p`
6164
FROM `Posts` AS `p`
@@ -66,6 +69,14 @@ public override async Task Delete_predicate_based_on_optional_navigation(bool as
6669
WHERE `b`.`Title` LIKE 'Arthur%'
6770
)
6871
""");
72+
}
73+
else
74+
{
75+
// Not supported by MySQL and older MariaDB versions:
76+
// Error Code: 1093. You can't specify target table 'p' for update in FROM clause
77+
await Assert.ThrowsAsync<MySqlException>(
78+
() => base.Delete_predicate_based_on_optional_navigation(async));
79+
}
6980
}
7081

7182
public override async Task Update_non_owned_property_on_entity_with_owned(bool async)
@@ -130,9 +141,11 @@ public override async Task Update_non_main_table_in_entity_with_entity_splitting
130141

131142
public override async Task Delete_entity_with_auto_include(bool async)
132143
{
133-
await base.Delete_entity_with_auto_include(async);
144+
if (AppConfig.ServerVersion.Supports.DeleteWithSelfReferencingSubquery)
145+
{
146+
await base.Delete_entity_with_auto_include(async);
134147

135-
AssertSql(
148+
AssertSql(
136149
"""
137150
DELETE `c`
138151
FROM `Context30572_Principal` AS `c`
@@ -142,6 +155,14 @@ public override async Task Delete_entity_with_auto_include(bool async)
142155
LEFT JOIN `Context30572_Dependent` AS `c1` ON `c0`.`DependentId` = `c1`.`Id`
143156
)
144157
""");
158+
}
159+
else
160+
{
161+
// Not supported by MySQL and older MariaDB versions:
162+
// Error Code: 1093. You can't specify target table 'c' for update in FROM clause
163+
await Assert.ThrowsAsync<MySqlException>(
164+
() => base.Delete_entity_with_auto_include(async));
165+
}
145166
}
146167

147168
public override async Task Update_with_alias_uniquification_in_setter_subquery(bool async)

0 commit comments

Comments
 (0)