From cc04270c2a6017830a1efccdfa9b30f9d2f53835 Mon Sep 17 00:00:00 2001 From: biss Date: Sat, 8 Aug 2026 15:37:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=B2=E4=BF=AE=E5=A4=8D=E5=AE=9E=E9=AA=8C?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E6=8E=92=E8=AF=BE=E6=8A=A5=E9=94=99=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ExperimentsController.cs | 2 +- tests/Jiaowu.Api.Tests/MySqlMigrationTests.cs | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/Jiaowu.Api/Controllers/ExperimentsController.cs b/src/Jiaowu.Api/Controllers/ExperimentsController.cs index dd54afd..b47f5b4 100644 --- a/src/Jiaowu.Api/Controllers/ExperimentsController.cs +++ b/src/Jiaowu.Api/Controllers/ExperimentsController.cs @@ -574,7 +574,7 @@ public sealed class ExperimentsController( var projects = await ScopedProjects() .Include(x => x.TeachingTask) .ThenInclude(x => x!.AcademicTerm) - .Where(x => projectIds.Contains(x.Id)) + .WhereIn(projectIds, x => x.Id) .ToDictionaryAsync(x => x.Id, cancellationToken); if (projects.Count != projectIds.Count) return ValidationProblem( diff --git a/tests/Jiaowu.Api.Tests/MySqlMigrationTests.cs b/tests/Jiaowu.Api.Tests/MySqlMigrationTests.cs index e1cf942..724dfeb 100644 --- a/tests/Jiaowu.Api.Tests/MySqlMigrationTests.cs +++ b/tests/Jiaowu.Api.Tests/MySqlMigrationTests.cs @@ -235,6 +235,39 @@ public sealed class MySqlMigrationTests StringComparison.OrdinalIgnoreCase); } + [Fact] + public void MySql_experiment_batch_project_query_is_translatable() + { + using var db = new AppDbContext(CreateMySqlOptions()); + var projectIds = new[] + { + Guid.Parse("11111111-1111-1111-1111-111111111111"), + Guid.Parse("22222222-2222-2222-2222-222222222222") + }; + var accessibleTaskIds = db.TeachingTasks.Select(x => x.Id); + + var sql = db.ExperimentProjects + .Where(x => accessibleTaskIds.Contains(x.TeachingTaskId)) + .Include(x => x.TeachingTask) + .ThenInclude(x => x!.AcademicTerm) + .WhereIn(projectIds, x => x.Id) + .ToQueryString(); + + Assert.Contains( + "ExperimentProjects", + sql, + StringComparison.OrdinalIgnoreCase); + Assert.Contains(" IN (", sql, StringComparison.OrdinalIgnoreCase); + Assert.Contains( + projectIds[0].ToString(), + sql, + StringComparison.OrdinalIgnoreCase); + Assert.Contains( + projectIds[1].ToString(), + sql, + StringComparison.OrdinalIgnoreCase); + } + [Fact] public void MySql_index_names_fit_the_server_identifier_limit() {