Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't return tracked objects from the dbContext to avoid clients modifying objects which EF tracks #21

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Core/QueryHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static class QueryHelpers
{
public static async Task<SyncState> GetSyncState(this IQueryable<CommitBase> 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());
Expand Down
2 changes: 1 addition & 1 deletion src/SIL.Harmony/Db/CrdtRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public IQueryable<T> GetCurrentObjects<T>() where T : class
{
if (_crdtConfig.Value.EnableProjectedTables)
{
return _dbContext.Set<T>();
return _dbContext.Set<T>().AsNoTracking();
}
throw new NotSupportedException("GetCurrentObjects is not supported when not using projected tables");
}
Expand Down