From 14632b5642938406af6dbd5e376894d2b482fd84 Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Fri, 29 Nov 2024 14:30:22 +0700 Subject: [PATCH] don't return tracked objects from the dbContext to avoid clients modifying objects which EF tracks --- src/SIL.Harmony.Core/QueryHelpers.cs | 2 +- src/SIL.Harmony/Db/CrdtRepository.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SIL.Harmony.Core/QueryHelpers.cs b/src/SIL.Harmony.Core/QueryHelpers.cs index 6562829..6be34e4 100644 --- a/src/SIL.Harmony.Core/QueryHelpers.cs +++ b/src/SIL.Harmony.Core/QueryHelpers.cs @@ -6,7 +6,7 @@ public static class QueryHelpers { public static async Task GetSyncState(this IQueryable commits) { - var dict = await commits.GroupBy(c => c.ClientId) + var dict = await commits.AsNoTracking().GroupBy(c => c.ClientId) .Select(g => new { ClientId = g.Key, DateTime = g.Max(c => c.HybridDateTime.DateTime) }) .AsAsyncEnumerable()//this is so the ticks are calculated server side instead of the db .ToDictionaryAsync(c => c.ClientId, c => c.DateTime.ToUnixTimeMilliseconds()); diff --git a/src/SIL.Harmony/Db/CrdtRepository.cs b/src/SIL.Harmony/Db/CrdtRepository.cs index 82efc83..fb86c6d 100644 --- a/src/SIL.Harmony/Db/CrdtRepository.cs +++ b/src/SIL.Harmony/Db/CrdtRepository.cs @@ -194,7 +194,7 @@ public IQueryable GetCurrentObjects() where T : class { if (_crdtConfig.Value.EnableProjectedTables) { - return _dbContext.Set(); + return _dbContext.Set().AsNoTracking(); } throw new NotSupportedException("GetCurrentObjects is not supported when not using projected tables"); }