ChangeTracking 2.0.22

There is a newer version of this package available.
See the version list below for details.
dotnet add package ChangeTracking --version 2.0.22                
NuGet\Install-Package ChangeTracking -Version 2.0.22                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ChangeTracking" Version="2.0.22" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ChangeTracking --version 2.0.22                
#r "nuget: ChangeTracking, 2.0.22"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ChangeTracking as a Cake Addin
#addin nuget:?package=ChangeTracking&version=2.0.22

// Install ChangeTracking as a Cake Tool
#tool nuget:?package=ChangeTracking&version=2.0.22                

Build status NuGet Badge Test status

ChangeTracking

Track changes in your POCO objects, and in your collections. By using Castle Dynamic Proxy to create proxies of your classes at runtime, you can use your objects just like you used to, and just by calling the AsTrackable() extension method, you get automatic change tracking, and cancellation.

All trackable POCOs implement IChangeTrackable<T>, IRevertibleChangeTracking, IChangeTracking, IEditableObject and INotifyPropertyChanged.

And all trackable collections implement IChangeTrackableCollection<T>, IBindingList ICancelAddNew, INotifyCollectionChanged , IList<T>, IList, ICollection<T>, ICollection, IEnumerable<T> and IEnumerable

Installation

PM> Install-Package ChangeTracking

Example

To make an object trackable

using ChangeTracking;
//...
Order order = new Order 
{ 
    Id = 1,
    CustumerNumber = "Test",
    Address = new Address
    {
        AddressId = 1,
        City = "New York"
    },
    OrderDetails = new List<OrderDetail>
    {
        new OrderDetail
        {
            OrderDetailId = 1,
            ItemNo = "Item123"
        },
        new OrderDetail
        {
            OrderDetailId = 2,
            ItemNo = "Item369"
        }
    }
};
Order trackedOrder = order.AsTrackable();

And here is how you get to the tracked info.

var trackable = (IChangeTrackable<Order>)trackedOrder;
// same as
var trackable = trackedOrder.CastToIChangeTrackable();

And here is what's available on trackable.

//Can be Unchanged, Added, Changed, Deleted
ChangeStatus status = trackable.ChangeTrackingStatus;

//Will be true if ChangeTrackingStatus is not Unchanged
bool isChanged = trackable.IsChanged;

//Will retrieve the original value of a property
string originalCustNumber = trackable.GetOriginalValue(o => o.CustumerNumber);

//Will retrieve a copy of the original item
var originalOrder = trackable.GetOriginal();

//Calling RejectChanges will reject all the changes you made, reset all properties to their original values and set ChangeTrackingStatus to Unchanged
trackable.RejectChanges();

//Calling AcceptChanges will accept all the changes you made, clears the original values and set ChangeTrackingStatus to Unchanged
trackable.AcceptChanges();

//If ChangeTrackingStatus is Changed it returns all changed property names, if ChangeTrackingStatus is Added or Deleted it returns all properties
trackable.ChangedProperties();

By default complex properties and collection properties will be tracked (if it can be made trackable) as well. if you do not wish to track them you can set it when creating the trackable.

var trackable = order.AsTrackable(makeComplexPropertiesTrackable: false);

or

var trackable = order.AsTrackable(makeCollectionPropertiesTrackable: false);

And on a collection

var orders = new List<Order>{new Order { Id = 1, CustumerNumber = "Test" } };
IList<Order> trackableOrders = orders.AsTrackable();

And here is how you get to the tracked info.

var trackable = (IChangeTrackableCollection<Order>)trackableOrders;
// Same as
var trackable = trackableOrders.CastToIChangeTrackableCollection();

And here is what's available on trackable.

// Will be true if there are any changed items, added items or deleted items in the collection.
bool isChanged = trackable.IsChanged;

// Will return all items with ChangeTrackingStatus of Unchanged
IEnumerable<Order> unchangedOrders = trackable.UnchangedItems;
// Will return all items that were added to the collection - with ChangeTrackingStatus of Added
IEnumerable<Order> addedOrders = trackable.AddedItems;
// Will return all items with ChangeTrackingStatus of Changed
IEnumerable<Order> changedOrders = trackable.ChangedItems;
// Will return all items that were removed from the collection - with ChangeTrackingStatus of Deleted
IEnumerable<Order> deletedOrders = trackable.DeletedItems;

// Will Accept all the changes in the collection and its items, deleted items will be cleared and all items ChangeTrackingStatus will be Unchanged
trackable.AcceptChanges();

// Will Reject all the changes in the collection and its items, deleted items will be moved back to the collection, added items removed and all items ChangeTrackingStatus will be Unchanged
trackable.RejectChanges();

Requirements and restrictions

  • .net 4.5.2 and above
  • netstandard 2.0
For Plain objects
  • Your class must not be sealed and all members in your class must be public virtual

    public class Order
    {
        public virtual int Id { get; set; }
        public virtual string CustumerNumber { get; set; }
        public virtual Address  Address { get; set; }
        public virtual IList<OrderDetail> OrderDetails { get; set; }
    }
    
For Collections
  • You can only assign the created proxy to one of the implemented interfaces, i.e. ICollection<T>, IList<T> and IBindingList, and the AsTrackable<T>() will choose the correct extennsion method only if called on IList<T>, IList, ICollection<T> and ICollection.

    IList<Order> orders = new List<Order>().AsTrackable();
    
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net452 is compatible.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on ChangeTracking:

Package Downloads
SmartLifeLtd

Official Library for Solutions The Library contains the main operations, data, utilities and Base forms for the Solutions. It's build using Visual Studio 2017, C# 7.0 and .Net framework 4.6.1 .

GoLive.Saturn.Auditing

Package Description

Ease.Repository

C#/.Net building blocks supporting implementation of the repository and unit of work patterns compatible with both NoSQL and SQL / session-aware stores. See Ease.Repository.* packages for concrete implementations.

Ease.Repository.AzureTable

C#/.Net building blocks supporting implementation of the repository and unit of work patterns for Azure Table.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.17 188,530 10/18/2019
2.2.16 1,100 10/4/2019
2.2.13 1,679 9/3/2019
2.2.4 1,603 7/16/2019
2.2.3 3,632 2/5/2019
2.2.2 931 1/30/2019
2.2.1 895 1/28/2019
2.2.0 915 1/24/2019
2.1.2 7,966 11/29/2018
2.1.1 1,065 11/1/2018
2.1.0 1,122 10/15/2018
2.0.22 2,836 9/6/2018
2.0.20 1,091 9/6/2018
2.0.13 2,131 7/18/2018
2.0.9 1,358 6/21/2018
2.0.6 4,156 5/28/2018
2.0.0 3,452 4/9/2018
2.0.0-Beta 1,094 1/28/2018
1.0.46 118,860 1/4/2017
1.0.44 1,324 12/1/2016
1.0.43 1,480 8/30/2016
1.0.38 1,985 10/30/2015
1.0.34 1,964 7/22/2015
1.0.26 1,735 11/11/2014
1.0.23 1,818 11/5/2014
1.0.22 1,384 10/2/2014
1.0.19 1,423 8/8/2014
1.0.17-beta 1,140 6/17/2014
1.0.16-beta 1,154 6/11/2014
1.0.15-beta 1,149 6/1/2014
0.0.9-alpha 1,173 5/20/2014
0.0.8-alpha 1,153 5/20/2014
0.0.7.2-alpha 1,123 5/14/2014