A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/NickStrupat/EntityFramework.TypedOriginalValues below:

NickStrupat/EntityFramework.TypedOriginalValues: Get typed access to the DbEntityEntry<T>.OriginalValues property bag

EntityFramework.TypedOriginalValues

Get typed access to the OriginalValues of your entity properties. Simple and complex properties are supported, navigation/collections are not.

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.

  1. Create an issue
  2. Let's find some point of agreement on your suggestion.
  3. Fork it!
  4. Create your feature branch: git checkout -b my-new-feature
  5. Commit your changes: git commit -am 'Add some feature'
  6. Push to the branch: git push origin my-new-feature
  7. Submit a pull request :D

Commit history

MIT License


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4