Get typed access to the OriginalValue
s of your entity properties. Simple and complex properties are supported, navigation/collections are not.
EF version | .NET support | NuGet package |
---|---|---|
6.1.3 | >= Framework 4.6.1 | |
Core 2.0 | >= Framework 4.6.1 || >= Standard 2.0 |
using (var context = new Context()) {
var me = await context.People.SingleAsync(x => x.Name == "Nick");
me.EmployeeNumber = 42; // change the value
// but wait! maybe we want to see what the value was inside some other mechanism, after we changed it (i.e. logging, auditing, etc.)
// old and busted
var og = (int) context.Entry(me).Property(nameof(EmployeeNumber)).OriginalValue;
// new hotness
var og = context.GetOriginal(me).EmployeeNumber;
await context.SaveChangesAsync(); // save that new value
}
A type is emitted at run-time which wraps the change tracking object of your DbContext
. This type inherits from your entity type, so you get typed access to its properties. It behaves like a read-only snapshot of your entities original state.
- Create an issue
- Let's find some point of agreement on your suggestion.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D