Skip to content

Commit

Permalink
Exposed DBContextBase.ChangedModelsList property
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Sep 19, 2019
1 parent 1a9f2f5 commit c4bc2bf
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/MongoDM/DBContextBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Digicando.MongoDM.ProxyModels;
using Digicando.MongoDM.Models;
using Digicando.MongoDM.ProxyModels;
using Digicando.MongoDM.Repositories;
using Digicando.MongoDM.Serialization;
using Digicando.MongoDM.Utility;
Expand Down Expand Up @@ -56,6 +57,10 @@ public DBContextBase(
}

// Public properties.
public IReadOnlyCollection<IEntityModel> ChangedModelsList =>
DBCache.LoadedModels.Values
.Where(model => (model as IAuditable).IsChanged)
.ToList();
public IMongoClient Client { get; }
public IMongoDatabase Database { get; }
public IDBCache DBCache { get; }
Expand Down Expand Up @@ -126,9 +131,7 @@ public virtual async Task SaveChangesAsync(CancellationToken cancellationToken =
//}

// Commit updated models replacement.
foreach (var model in DBCache.LoadedModels.Values
.Where(model => (model as IAuditable).IsChanged)
.ToList())
foreach (var model in ChangedModelsList)
{
var modelType = model.GetType().BaseType;
if (ModelCollectionRepositoryMap.ContainsKey(modelType)) //can't replace if is a file
Expand Down

0 comments on commit c4bc2bf

Please sign in to comment.