Skip to content

Commit f400e26

Browse files
authored
don't return tracked objects from the dbContext to avoid clients modifying objects which EF tracks (#21)
1 parent 3a5d037 commit f400e26

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/SIL.Harmony.Core/QueryHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public static class QueryHelpers
66
{
77
public static async Task<SyncState> GetSyncState(this IQueryable<CommitBase> commits)
88
{
9-
var dict = await commits.GroupBy(c => c.ClientId)
9+
var dict = await commits.AsNoTracking().GroupBy(c => c.ClientId)
1010
.Select(g => new { ClientId = g.Key, DateTime = g.Max(c => c.HybridDateTime.DateTime) })
1111
.AsAsyncEnumerable()//this is so the ticks are calculated server side instead of the db
1212
.ToDictionaryAsync(c => c.ClientId, c => c.DateTime.ToUnixTimeMilliseconds());

src/SIL.Harmony/Db/CrdtRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public IQueryable<T> GetCurrentObjects<T>() where T : class
194194
{
195195
if (_crdtConfig.Value.EnableProjectedTables)
196196
{
197-
return _dbContext.Set<T>();
197+
return _dbContext.Set<T>().AsNoTracking();
198198
}
199199
throw new NotSupportedException("GetCurrentObjects is not supported when not using projected tables");
200200
}

0 commit comments

Comments
 (0)