diff --git a/src/FilterLists.Services/SnapshotService/SnapshotBatchDe.cs b/src/FilterLists.Services/SnapshotService/SnapshotBatchDe.cs index d6e6512af..6a0ab7c6a 100644 --- a/src/FilterLists.Services/SnapshotService/SnapshotBatchDe.cs +++ b/src/FilterLists.Services/SnapshotService/SnapshotBatchDe.cs @@ -31,7 +31,7 @@ public void SaveSnapshotBatch() private void AddNewRules() { - preExistingSnapshotRules = dbContext.Rules.Where(rule => rawRules.Contains(rule.Raw)).AsNoTracking(); + preExistingSnapshotRules = dbContext.Rules.Where(rule => rawRules.Contains(rule.Raw)); var newSnapshotRawRules = rawRules.Except(preExistingSnapshotRules.Select(x => x.Raw)); newSnapshotRules = newSnapshotRawRules.Select(newSnapshotRawRule => new Rule {Raw = newSnapshotRawRule}) .ToList(); @@ -40,10 +40,21 @@ private void AddNewRules() private void AddSnapshotRules() { - snapshot.SnapshotRules = preExistingSnapshotRules - .Concat(newSnapshotRules) - .Select(rule => new SnapshotRule {Rule = rule, Snapshot = snapshot}) - .ToList(); + if (snapshot.SnapshotRules == null) + snapshot.SnapshotRules = new List(); + snapshot.SnapshotRules.AddRange(preExistingSnapshotRules + .Concat(newSnapshotRules) + .Select(rule => new SnapshotRule {Rule = rule, Snapshot = snapshot}) + .ToList()); + } + } + + public static class CollectionExtensions + { + public static void AddRange(this ICollection destination, IEnumerable source) + { + foreach (var item in source) + destination.Add(item); } } } \ No newline at end of file