DeepDiff 1.10.1

dotnet add package DeepDiff --version 1.10.1
                    
NuGet\Install-Package DeepDiff -Version 1.10.1
                    
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="DeepDiff" Version="1.10.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DeepDiff" Version="1.10.1" />
                    
Directory.Packages.props
<PackageReference Include="DeepDiff" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DeepDiff --version 1.10.1
                    
#r "nuget: DeepDiff, 1.10.1"
                    
#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.
#:package DeepDiff@1.10.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DeepDiff&version=1.10.1
                    
Install as a Cake Addin
#tool nuget:?package=DeepDiff&version=1.10.1
                    
Install as a Cake Tool

Breaking changes

1.10.0

  • to configure an entity, you must now use the ConfigureEntity<TEntity>() method instead of Entity<TEntity>()

Sample

How do I get started

First configure DeepDiff to know what types you want to compare, in the startup of your application

var diffConfiguration = new DiffConfiguration();
diffConfiguration.ConfigureEntity<Entity>()
   .HasKey(x => new { x.StartsOn, x.Name })
   .HasValues(x => new { x.Price, x.Volume })
   .HasMany(x => x.SubEntities)
   .OnInsert(cfg => cfg.SetValue(x => x.PersistChange, PersistChange.Insert))
   .OnUpdate(cfg => cfg.SetValue(x => x.PersistChange, PersistChange.Update))
   .OnDelete(cfg => cfg.SetValue(x => x.PersistChange, PersistChange.Delete));
diffConfiguration.ConfigureEntity<SubEntity>()
   .HasKey(x => x.SubName)
   .HasValues(x => x.Energy)
   .OnInsert(cfg => cfg.SetValue(x => x.PersistChange, PersistChange.Insert))
   .OnUpdate(cfg => cfg.SetValue(x => x.PersistChange, PersistChange.Update))
   .OnDelete(cfg => cfg.SetValue(x => x.PersistChange, PersistChange.Delete))
var deepDiff = diffConfiguration.CreateDeepDiff();

Then in your application code, this will detect insert/update/delete between existing and new entities. In case of update, properties will be copied from new to existing entity

var resultEntities = deepDiff.MergeMany(existingEntities, newEntities); // resultEntities will contain 'merged' entities

Sample entities definition

public class Entity
{
  public Guid Id { get; set; } // DB Key
  public DateTime StartsOn { get; set; } // Business Key
  public string Name { get; set; } // Business Key
  public decimal Price { get; set; }
  public int Volume { get; set; }
  public PersistChange PersistChange { get; set; }
  public List<SubEntity> SubEntities { get; set; }
}

public class SubEntity
{
  public Guid Id { get; set; } // DB Key
  public string SubName { get; set; } // Business Key
  public int Energy { get; set; }
  public PersistChange PersistChange { get; set; }
  public Guid EntityId { get; set; } // Foreign Key
}

public enum PersistChange
{
  None,
  Inserted,
  Updated,
  Deleted
}

Entity Configuration

HasKey

Defines properties used to compare and detect an insert and a delete. Mandatory unless NoKey has been defined

IEntityConfiguration<TEntity> HasKey<TKey>(Expression<Func<TEntity, TKey>> keyExpression)
IEntityConfiguration<TEntity> HasKey<TKey>(Expression<Func<TEntity, TKey>> keyExpression, Action<IKeyConfiguration<TEntity>> keyConfigurationAction)

HasValues

Defines properties used to detect an update in case keys are identical

IEntityConfiguration<TEntity> HasValues<TValue>(Expression<Func<TEntity, TValue>> valuesExpression)
IEntityConfiguration<TEntity> HasValues<TValue>(Expression<Func<TEntity, TValue>> valuesExpression, Action<IValuesConfiguration<TEntity>> valuesConfigurationAction)

HasOne

Defines property to navigate to a single child

IEntityConfiguration<TEntity> HasOne<TChildEntity>(Expression<Func<TEntity, TChildEntity>> navigationPropertyExpression)
IEntityConfiguration<TEntity> HasOne<TChildEntity>(Expression<Func<TEntity, TChildEntity>> navigationPropertyExpression, Action<INavigationOneConfiguration<TEntity, TChildEntity>> navigationOneConfigurationAction)

HasMany

Defines property to navigate to multiple children

IEntityConfiguration<TEntity> HasMany<TChildEntity>(Expression<Func<TEntity, List<TChildEntity>>> navigationPropertyExpression)
IEntityConfiguration<TEntity> HasMany<TChildEntity>(Expression<Func<TEntity, List<TChildEntity>>> navigationPropertyExpression, Action<INavigationManyConfiguration<TEntity, TChildEntity>> navigationManyConfigurationAction)

UseDerivedTypes

When set to true, engine will use force comparison by type if children are inherited and children collection is not abstract

INavigationManyConfiguration<TEntity, TChildEntity> UseDerivedTypes(bool use = false)

OnInsert

Defines operations to perform when an insert is detected

IEntityConfiguration<TEntity> OnInsert(Action<IInsertConfiguration<TEntity>> insertConfigurationAction)

SetValue

When an insert is detected, overwrite a property with a specific value

IInsertConfiguration<TEntity> SetValue<TMember>(Expression<Func<TEntity, TMember>> destinationMember, TMember value)

OnUpdate

Defines operations to perform when an insert is detected. Properties specified in Values(...) will automatically be copied from new entity to existing one

IEntityConfiguration<TEntity> OnUpdate(Action<IUpdateConfiguration<TEntity>> updateConfigurationAction)

SetValue

When an update is detected, overwrite a property with a specific value

IUpdateConfiguration<TEntity> SetValue<TMember>(Expression<Func<TEntity, TMember>> destinationMember, TMember value)

CopyValues

When an update is detected, specify additional properties to copy from new entity to existing one

IUpdateConfiguration<TEntity> CopyValues<TValue>(Expression<Func<TEntity, TValue>> copyValuesExpression)

OnDelete

Defines operations to perform when a delete is detected.

IEntityConfiguration<TEntity> OnDelete(Action<IDeleteConfiguration<TEntity>> deleteConfigurationAction)

SetValue

When a delete is detected, overwrite property with a specific value

IDeleteConfiguration<TEntity> SetValue<TMember>(Expression<Func<TEntity, TMember>> destinationMember, TMember value)

WithComparer

Defines the IEqualityComparer to use when comparing entity of that type

IEntityConfiguration<TEntity> WithComparer<T>(IEqualityComparer<T> equalityComparer)

ForceUpdateIf

Defines additional criteria to force an update even if no update is detected using entity value(s).

IEntityConfiguration<TEntity> ForceUpdateIf(Action<IForceUpdateIfConfiguration<TEntity>> forceUpdateIfConfigurationAction)

NestedEntitiesModified

Trigger an update when a nested entity is modified

IForceUpdateIfConfiguration<TEntity> NestedEntitiesModified()

Equals

Trigger an update when an equality condition is met

IForceUpdateIfConfiguration<TEntity> Equals<TMember>(Expression<Func<TEntity, TMember>> compareToMember, TMember compareToValue)

Ignore

Defines entity properties which will not be found anywhere in the entity diff configuration. This will be used by ValidateIfEveryPropertiesAreReferenced

IEntityConfiguration<TEntity> Ignore<TIgnore>(Expression<Func<TEntity, TIgnore>> ignoreExpression)

NoKey

Defines a no key entity, only update will be deteted for this kind of entity. Mandatory if no HasKey has been defined

IEntityConfiguration<TEntity> NoKey()

Engine configuration

MergeSingle

TEntity MergeSingle<TEntity>(TEntity existingEntity, TEntity newEntity)
TEntity MergeSingle<TEntity>(TEntity existingEntity, TEntity newEntity, IOperationListener operationListener)
TEntity MergeSingle<TEntity>(TEntity existingEntity, TEntity newEntity, Action<IMergeSingleConfiguration> mergeSingleConfigurationAction)
TEntity MergeSingle<TEntity>(TEntity existingEntity, TEntity newEntity, IOperationListener operationListener, Action<IMergeSingleConfiguration> mergeSingleConfigurationAction)

MergeMany

IEnumerable<TEntity> MergeMany<TEntity>(IEnumerable<TEntity> existingEntities, IEnumerable<TEntity> newEntities)
IEnumerable<TEntity> MergeMany<TEntity>(IEnumerable<TEntity> existingEntities, IEnumerable<TEntity> newEntities, IOperationListener operationListener)
IEnumerable<TEntity> MergeMany<TEntity>(IEnumerable<TEntity> existingEntities, IEnumerable<TEntity> newEntities, Action<IMergeManyConfiguration> mergeManyConfigurationAction)
IEnumerable<TEntity> MergeMany<TEntity>(IEnumerable<TEntity> existingEntities, IEnumerable<TEntity> newEntities, IOperationListener operationListener, Action<IMergeManyConfiguration> mergeManyConfigurationAction)

CompareSingle

void CompareSingle<TEntity>(TEntity existingEntity, TEntity newEntity, IOperationListener operationListener);
void CompareSingle<TEntity>(TEntity existingEntity, TEntity newEntity, IOperationListener operationListener, Action<ICompareSingleConfiguration> compareSingleConfigurationAction);

CompareMany

void CompareMany<TEntity>(IEnumerable<TEntity> existingEntities, IEnumerable<TEntity> newEntities, IOperationListener operationListener);
void CompareMany<TEntity>(IEnumerable<TEntity> existingEntities, IEnumerable<TEntity> newEntities, IOperationListener operationListener, Action<ICompareManyConfiguration> compareManyConfigurationAction);

MergeSingle configuration

UseHashtable

When set to true, hashtable will be used when searching in a collection of entities with a minimum HashtableThreshold (15 by default) entries (true by default)

IMergeSingleConfiguration UseHashtable(bool use = true)

HashtableThreshold

Defines minimum number of entries in collection to use hashtable (15 by default)

IMergeSingleConfiguration HashtableThreshold(int threshold = 15)

ForceOnUpdateWhenModificationsDetectedOnlyInNestedLevel

Force OnUpdate to be triggered if a nested entity has been modified even if current entity is not modified

IMergeSingleConfiguration ForceOnUpdateWhenModificationsDetectedOnlyInNestedLevel(bool force = false)

SetEqualityComparer

Choose which equality comparer engine will use to compare keys and values (Precompiled by default)

IMergeSingleConfiguration SetEqualityComparer(EqualityComparers equalityComparer = EqualityComparers.Precompiled)

MergeMany configuration

UseHashtable

When set to true, hashtable will be used when searching in a collection of entities with a minimum HashtableThreshold (15 by default) entries (true by default)

IMergeManyConfiguration UseHashtable(bool use = true)

HashtableThreshold

Defines minimum number of entries in collection to use hashtable (15 by default)

IMergeManyConfiguration HashtableThreshold(int threshold = 15)

ForceOnUpdateWhenModificationsDetectedOnlyInNestedLevel

Force OnUpdate to be triggered if a nested entity has been modified even if current entity is not modified

IMergeManyConfiguration ForceOnUpdateWhenModificationsDetectedOnlyInNestedLevel(bool force = false)

SetEqualityComparer

Choose which equality comparer engine will use to compare keys and values (Precompiled by default)

IMergeManyConfiguration SetEqualityComparer(EqualityComparers equalityComparer = EqualityComparers.Precompiled)

CompareSingle configuration

UseHashtable

When set to true, hashtable will be used when searching in a collection of entities with a minimum HashtableThreshold (15 by default) entries (true by default)

ICompareSingleConfiguration UseHashtable(bool use = true);

HashtableThreshold

Defines minimum number of entries in collection to use hashtable (15 by default)

ICompareSingleConfiguration HashtableThreshold(int threshold = 15);

SetEqualityComparer

Choose which equality comparer engine will use to compare keys and values (Precompiled by default)

ICompareSingleConfiguration SetEqualityComparer(EqualityComparers equalityComparer = EqualityComparers.Precompiled)

CompareMany configuration

UseHashtable

When set to true, hashtable will be used when searching in a collection of entities with a minimum HashtableThreshold (15 by default) entries (true by default)

ICompareManyConfiguration UseHashtable(bool use = true);

HashtableThreshold

Defines minimum number of entries in collection to use hashtable (15 by default)

ICompareManyConfiguration HashtableThreshold(int threshold = 15);

SetEqualityComparer

Choose which equality comparer engine will use to compare keys and values (Precompiled by default)

ICompareManyConfiguration SetEqualityComparer(EqualityComparers equalityComparer = EqualityComparers.Precompiled)

OperationListener

Defines a listener which will be called on every insert/update/delete detection

OnInsert

void OnDelete(string entityName, Func<Dictionary<string, object>> getKeysFunc, Func<Dictionary<string, Dictionary<string, object>>> getNavigationParentKeysFunc);

OnDelete

void OnInsert(string entityName, Func<Dictionary<string, object>> getKeysFunc, Func<Dictionary<string, Dictionary<string, object>>> getNavigationParentKeysFunc);

OnUpdate

void OnUpdate(string entityName, string propertyName, Func<Dictionary<string, object>> getKeysFunc, Func<object> getOriginalValueFunc, Func<Dictionary<string, Dictionary<string, object>>> getNavigationParentKeysFunc);

Deep Diff Configuration

ConfigureEntity

Create an entity configuration

IEntityConfiguration<TEntity> ConfigureEntity<TEntity>()

AddProfile

Add diff profile

IDeepDiffConfiguration AddProfile<TProfile>()
IDeepDiffConfiguration AddProfile(DiffProfile diffProfile)

AddProfiles

Scan assemblies and add diff profile found in those assemblies

IDeepDiffConfiguration AddProfiles(params Assembly[] assembliesToScan)

CreateDeepDiff

Create DeepDiff engine (also validate configuration)

IDeepDiff CreateDeepDiff()

ValidateConfiguration

Validate entity configurations

void ValidateConfiguration()

ValidateIfEveryPropertiesAreReferenced

Check if every properties found in configured entities are used in configuration, use Ignore to add properties to ignore in this validation

void ValidateIfEveryPropertiesAreReferenced()
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DeepDiff:

Package Downloads
DeepDiff.Extensions.Microsoft.DependencyInjection

DeepDeef extensions for Microsft Dependendy Injection

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.10.1 173 5/7/2025
1.10.0 142 4/11/2025
1.9.5 178 4/7/2025
1.9.4 177 4/7/2025
1.9.3 110 4/5/2025
1.9.2 128 4/4/2025
1.9.1 165 3/13/2025
1.9.0 239 3/4/2025
1.8.9 117 2/26/2025
1.8.8 108 2/26/2025
1.8.7 114 2/25/2025
1.8.6 115 2/25/2025
1.8.5 112 1/22/2025
1.8.4 121 1/21/2025
1.8.3 109 1/8/2025
1.8.2 158 7/2/2024
1.8.1 139 6/27/2024
1.8.0 132 6/21/2024
1.7.0 156 4/30/2024
1.6.4 143 4/26/2024
1.6.3 151 3/15/2024
1.6.2 147 2/27/2024
1.6.1 145 2/26/2024
1.6.0 141 2/22/2024
1.5.1 170 2/14/2024
1.5.0 461 1/31/2024
1.4.2 126 1/30/2024
1.4.1 129 1/30/2024
1.4.0 136 1/29/2024
1.3.6 138 1/27/2024
1.3.5 132 1/26/2024
1.3.4 126 1/26/2024
1.3.3 159 1/26/2024
1.3.2 133 1/25/2024
1.3.1 136 1/24/2024
1.3.0 139 1/24/2024
1.2.3 142 1/18/2024
1.2.2 150 1/9/2024
1.2.1 181 12/15/2023
1.1.1 157 12/7/2023
1.1.0 197 12/4/2023
1.0.2 189 12/2/2023
1.0.1 187 12/1/2023
1.0.0 145 12/1/2023