DeepDiff 1.7.0
See the version list below for details.
dotnet add package DeepDiff --version 1.7.0
NuGet\Install-Package DeepDiff -Version 1.7.0
<PackageReference Include="DeepDiff" Version="1.7.0" />
paket add DeepDiff --version 1.7.0
#r "nuget: DeepDiff, 1.7.0"
// Install DeepDiff as a Cake Addin #addin nuget:?package=DeepDiff&version=1.7.0 // Install DeepDiff as a Cake Tool #tool nuget:?package=DeepDiff&version=1.7.0
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.Entity<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.Entity<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 result = deepDiff.DiffMany(existingEntities, newEntities); // result.Entities will contain 'diff' 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)
UsePrecompiledEqualityComparer
When set to true, engine will use optimized equality comparers to compare keys and values (true by default)
IKeyConfiguration<TEntity> UsePrecompiledEqualityComparer(bool use = true)
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)
UsePrecompiledEqualityComparer
When set to true, engine will use optimized equality comparers to compare keys and values (true by default)
IValuesConfiguration<TEntity> UsePrecompiledEqualityComparer(bool use = true)
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 navigation 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)
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)
GenerateOperations
When set to true, insert operations will be logged (true by default) in the result
IInsertConfiguration<TEntity> GenerateOperations(bool generate = true)
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)
GenerateOperations
When set to true, update operations will be logged (true by default) in the result
IUpdateConfiguration<TEntity> GenerateOperations(bool generate = true)
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)
GenerateOperations
When set to true, delete operations will be logged (true by default) in the result
IDeleteConfiguration<TEntity> GenerateOperations(bool generate = true)
WithComparer
Defines the IEqualityComparer to use when comparing entity of that type
IEntityConfiguration<TEntity> WithComparer<T>(IEqualityComparer<T> equalityComparer)
ForceUpdateIf
Defines additional criteria to detect an update even if Values are identical
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 set
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
DiffSingle
DiffSingleResult<TEntity> DiffSingle<TEntity>(TEntity existingEntity, TEntity newEntity)
DiffSingleResult<TEntity> DiffSingle<TEntity>(TEntity existingEntity, TEntity newEntity, Action<IDiffSingleConfiguration> diffSingleConfigurationAction)
DiffMany
DiffManyResult<TEntity> DiffMany<TEntity>(IEnumerable<TEntity> existingEntities, IEnumerable<TEntity> newEntities)
DiffManyResult<TEntity> DiffMany<TEntity>(IEnumerable<TEntity> existingEntities, IEnumerable<TEntity> newEntities, Action<IDiffManyConfiguration> diffManyConfigurationAction)
DiffSingle 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)
IDiffSingleConfiguration UseHashtable(bool use = true)
HashtableThreshold
Defines minimum number of entries in collection to use hashtable (15 by default)
IDiffSingleConfiguration HashtableThreshold(int threshold = 15)
ForceOnUpdateEvenIfModificationsDetectedOnlyInNestedLevel
Force OnUpdate to be triggered if a nested entity has been modified even if current entity is not modified
IDiffSingleConfiguration ForceOnUpdateEvenIfModificationsDetectedOnlyInNestedLevel(bool force = false)
GenerateOperations
When set to true, engine will generate a collection of operations detected when performing diff (true by default)
IDiffSingleConfiguration GenerateOperations(bool generate = true)
OnlyGenerateOperations
When set to true, engine will ONLY generate a collection of operations detected when performing diff and no modification will be applied to entities (false by default)
IDiffSingleConfiguration OnlyGenerateOperations(bool onlyGenerate = false)
UsePrecompiledEqualityComparer
When set to true, engine will use optimized equality comparers to compare keys and values (true by default)
IDiffSingleConfiguration UsePrecompiledEqualityComparer(bool use = true)
DiffMany 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)
IDiffManyConfiguration UseHashtable(bool use = true)
HashtableThreshold
Defines minimum number of entries in collection to use hashtable (15 by default)
IDiffManyConfiguration HashtableThreshold(int threshold = 15)
ForceOnUpdateEvenIfModificationsDetectedOnlyInNestedLevel
Force OnUpdate to be triggered if a nested entity has been modified even if current entity is not modified
IDiffManyConfiguration ForceOnUpdateEvenIfModificationsDetectedOnlyInNestedLevel(bool force = false)
GenerateOperations
When set to true, engine will generate a collection of operations detected when performing diff (true by default)
IDiffManyConfiguration GenerateOperations(bool generate = true)
OnlyGenerateOperations
When set to true, engine will ONLY generate a collection of operations detected when performing diff and no modification will be applied to entities (false by default)
IDiffManyConfiguration OnlyGenerateOperations(bool onlyGenerate = false)
UsePrecompiledEqualityComparer
When set to true, engine will use optimized equality comparers to compare keys and values (true by default)
IDiffManyConfiguration UsePrecompiledEqualityComparer(bool use = true)
Deep Diff Configuration
Entity
Create an entity configuration
IEntityConfiguration<TEntity> Entity<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()
Diff operations
InsertDiffOperation
Keys
Keys of entity on which insert has been performed
EntityName
Name of entity on which insert has been performed
UpdateDiffOperation
Keys
Keys of entity on which update has been performed
EntityName
Name of entity on which update has been performed
UpdatedProperties
Collection of properties from Values configuration on which update has been performed
SetValueProperties
Collection of properties on which SetValue has been performed
CopyValuesProperties
Collection of properties on which CopyValues has been performed
DeleteDiffOperation
Keys
Keys of entity on which delete has been performed
EntityName
Name of entity on which delete has been performed
Product | Versions 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 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. |
-
net5.0
- No dependencies.
-
net6.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.8.2 | 90 | 7/2/2024 |
1.8.1 | 88 | 6/27/2024 |
1.8.0 | 85 | 6/21/2024 |
1.7.0 | 109 | 4/30/2024 |
1.6.4 | 100 | 4/26/2024 |
1.6.3 | 107 | 3/15/2024 |
1.6.2 | 98 | 2/27/2024 |
1.6.1 | 95 | 2/26/2024 |
1.6.0 | 97 | 2/22/2024 |
1.5.1 | 122 | 2/14/2024 |
1.5.0 | 285 | 1/31/2024 |
1.4.2 | 82 | 1/30/2024 |
1.4.1 | 84 | 1/30/2024 |
1.4.0 | 84 | 1/29/2024 |
1.3.6 | 87 | 1/27/2024 |
1.3.5 | 86 | 1/26/2024 |
1.3.4 | 84 | 1/26/2024 |
1.3.3 | 97 | 1/26/2024 |
1.3.2 | 86 | 1/25/2024 |
1.3.1 | 86 | 1/24/2024 |
1.3.0 | 82 | 1/24/2024 |
1.2.3 | 97 | 1/18/2024 |
1.2.2 | 103 | 1/9/2024 |
1.2.1 | 141 | 12/15/2023 |
1.1.1 | 113 | 12/7/2023 |
1.1.0 | 138 | 12/4/2023 |
1.0.2 | 137 | 12/2/2023 |
1.0.1 | 123 | 12/1/2023 |
1.0.0 | 92 | 12/1/2023 |