diff --git a/Disco.Data/Properties/AssemblyInfo.cs b/Disco.Data/Properties/AssemblyInfo.cs index 59b2ff10..7d881942 100644 --- a/Disco.Data/Properties/AssemblyInfo.cs +++ b/Disco.Data/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.0411.1908")] -[assembly: AssemblyFileVersion("1.2.0411.1908")] +[assembly: AssemblyVersion("1.2.0430.1219")] +[assembly: AssemblyFileVersion("1.2.0430.1219")] diff --git a/Disco.Data/Repository/Monitor/RepositoryMonitor.cs b/Disco.Data/Repository/Monitor/RepositoryMonitor.cs index b739b17a..e5c87736 100644 --- a/Disco.Data/Repository/Monitor/RepositoryMonitor.cs +++ b/Disco.Data/Repository/Monitor/RepositoryMonitor.cs @@ -79,9 +79,11 @@ namespace Disco.Data.Repository.Monitor var entryState = stateManager.GetObjectStateEntry(monitorEvent.Entity); monitorEvent.EntityKey = entryState.EntityKey.EntityKeyValues.Select(kv => kv.Value).ToArray(); } + + monitorEvent.afterCommit = true; } - internal static RepositoryMonitorEvent EventFromEntryState(DiscoDataContext dbContext, DbEntityEntry dbEntryState, ObjectStateEntry entryState) + internal static RepositoryMonitorEvent EventFromEntryState(DiscoDataContext dbContext, DbEntityEntry dbEntryState, ObjectStateEntry objectEntryState) { RepositoryMonitorEventType eventType; string[] modifiedProperties = null; @@ -113,14 +115,16 @@ namespace Disco.Data.Repository.Monitor // Only pass modified properties on Modified Event (Ignore Added/Deleted) if (eventType == RepositoryMonitorEventType.Modified) - modifiedProperties = entryState.GetModifiedProperties().ToArray(); + modifiedProperties = objectEntryState.GetModifiedProperties().ToArray(); // Don't pass entity key when entity newly added if (eventType != RepositoryMonitorEventType.Added) - entityKey = entryState.EntityKey.EntityKeyValues.Select(kv => kv.Value).ToArray(); + entityKey = objectEntryState.EntityKey.EntityKeyValues.Select(kv => kv.Value).ToArray(); return new RepositoryMonitorEvent() { + dbEntityState = dbEntryState, + objectEntryState = objectEntryState, dbContext = dbContext, EventType = eventType, Entity = dbEntryState.Entity, diff --git a/Disco.Data/Repository/Monitor/RepositoryMonitorEvent.cs b/Disco.Data/Repository/Monitor/RepositoryMonitorEvent.cs index d355693d..cf3cc5ca 100644 --- a/Disco.Data/Repository/Monitor/RepositoryMonitorEvent.cs +++ b/Disco.Data/Repository/Monitor/RepositoryMonitorEvent.cs @@ -1,6 +1,8 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.Data.Entity.Infrastructure; +using System.Data.Objects; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,6 +11,13 @@ namespace Disco.Data.Repository.Monitor { public class RepositoryMonitorEvent { + [JsonIgnore] + internal ObjectStateEntry objectEntryState { get; set; } + [JsonIgnore] + internal DbEntityEntry dbEntityState { get; set; } + [JsonIgnore] + internal bool afterCommit { get; set; } + [JsonIgnore] public DiscoDataContext dbContext { get; set; } @@ -31,5 +40,17 @@ namespace Disco.Data.Repository.Monitor public object[] EntityKey { get; set; } public string[] ModifiedProperties { get; set; } + + public T GetPreviousPropertyValue(string PropertyName) + { + if (afterCommit) + throw new InvalidOperationException("Unable to determine property values after repository commit"); + else + return (T)dbEntityState.OriginalValues[PropertyName]; + } + public T GetCurrentPropertyValue(string PropertyName) + { + return (T)dbEntityState.CurrentValues[PropertyName]; + } } }