πŸ”“β“ Matched and One NOT Condition Option in Entity Framework ExtensionsUpdate only when at least one value is different

The MatchedAndOneNotCondition option in Entity Framework Extensions lets you perform the UPDATE action only when at least one selected value in the source and destination is different.

If all selected values are equal, the update is skipped. This gives you more precise control over when updates should happen β€” for example, to ignore insignificant changes, update only important fields, or optimize imports by avoiding unnecessary updates.

// @nuget: Z.EntityFramework.Extensions.EFCore
using Z.EntityFramework.Extensions;

context.BulkMerge(customers, options => 
{
    // ON UPDATE: only update if "Name" or "Email" is different between source and destination
    options.MergeMatchedAndOneNotConditionExpression = x => new { x.Name, x.Email };
});

Typical scenarios include:

  • Audit fields (ModifiedDate, ModifiedBy) β†’ Only update when at least one of these changes, skipping updates that don’t touch metadata.
  • Contact info (Phone, Email) β†’ Ensure updates are made only when at least one contact detail is different, ignoring other non-critical fields.
  • Product pricing (Price, Discount) β†’ Update records only if the pricing-related values have changed, skipping cosmetic changes like Description.
  • User profile (Name, Email, Role) β†’ Prevent unnecessary updates unless a meaningful field like name, email, or role has been modified.

This option applies to the following methods in Entity Framework Extensions:


πŸ’‘ Example Effect

ID Destination.Name Source.Name Destination.Email Source.Email Without Condition With Condition
1 John John john@a.com john@a.com updated skipped
2 John Johnny john@a.com john@a.com updated updated
3 John John john@a.com johnny@a.com updated updated

πŸ› οΈ Prerequisites

Before continuing, we recommend reading these articles first to understand how EF Extensions options work and the differences between column option types:

  • Configure Options – Learn the basics of setting and customizing options in EF Extensions.
  • Configure Column Options – See how to configure column-specific behavior and when to use Expression (strongly typed, compile-time safe) vs. Names (string-based, dynamic at runtime).

πŸ“Œ When to Use

Use the MatchedAndOneNotCondition option from Entity Framework Extensions when:

  • You want to update only if at least one key field has changed
  • You need to ignore changes in unimportant fields
  • You want to optimize synchronization by skipping updates when nothing meaningful has changed

⭐ Why It’s Useful

Without MatchedAndOneNotCondition, using in EF Core a bulk operations like BulkUpdate, BulkMerge, or BulkSynchronize from Entity Framework Extensions could update rows unnecessarily, even when the data hasn’t really changed.

Using this option, you can:

  • Prevent redundant updates
  • Focus updates only on meaningful differences
  • Simplify logic and avoid writing custom SQL

🏒 Scenario

A company imports customers using BulkMerge method from Entity Framework Extensions in EF Core.

  • The Note column often changes, but it’s not important enough to trigger an update.
  • The system should only update a row when critical fields like Name or Email are different.

In summary:

  • If Name or Email differs β†’ update the customer
  • If both are equal β†’ skip the update, even if other fields (like Note) changed

πŸ—οΈ Solution

The MatchedAndOneNotCondition option offers four ways to configure behavior:


🏷️ [Action]MatchedAndOneNotConditionExpression

Use this option to specify β€” with a lambda expression β€” which property values should be compared. If at least one property value is different, the update is executed.

context.BulkMerge(customers, options => 
{
    // ON UPDATE: perform update only when "Name" or "Email" differ between source and destination
    options.MergeMatchedAndOneNotConditionExpression = x => new { x.Name, x.Email };
});
Method Option Name Try it
BulkMerge MergeMatchedAndOneNotConditionExpression Online Example
BulkUpdate UpdateMatchedAndOneNotConditionExpression Online Example
BulkSynchronize SynchronizeMatchedAndOneNotConditionExpression Online Example

🏷️ [Action]MatchedAndOneNotConditionNames

Use this option to specify β€” with a list of property names β€” which property values should be compared. If at least one property value is different, the update is executed.

context.BulkMerge(customers, options => 
{
    options.MergeMatchedAndOneNotConditionNames = new List<string>() 
    { 
        nameof(Customer.Name), nameof(Customer.Email) 
    };
});
Method Option Name Try it
BulkMerge MergeMatchedAndOneNotConditionNames Online Example
BulkUpdate UpdateMatchedAndOneNotConditionNames Online Example
BulkSynchronize SynchronizeMatchedAndOneNotConditionNames Online Example

🏷️ IgnoreOn[Action]MatchedAndOneNotConditionExpression

Use this option to specify β€” with a lambda expression β€” which property values should be excluded from comparison. All other property values will be checked, and if at least one is different, the update is executed.

context.BulkMerge(customers, options => 
{
    // Exclude Note β†’ it won’t trigger updates
    options.IgnoreOnMergeMatchedAndOneNotConditionExpression = x => new { x.Note };
});
Method Option Name Try it
BulkMerge IgnoreOnMergeMatchedAndOneNotConditionExpression Online Example
BulkUpdate IgnoreOnUpdateMatchedAndOneNotConditionExpression Online Example
BulkSynchronize IgnoreOnSynchronizeMatchedAndOneNotConditionExpression Online Example

🏷️ IgnoreOn[Action]MatchedAndOneNotConditionNames

Use this option to specify β€” with a list of property names β€” which property values should be excluded from comparison. All other property values will be checked, and if at least one is different, the update is executed.

context.BulkMerge(customers, options => 
{
    options.IgnoreOnMergeMatchedAndOneNotConditionNames = new List<string>() { nameof(Customer.Note) };
});
Method Option Name Try it
BulkMerge IgnoreOnMergeMatchedAndOneNotConditionNames Online Example
BulkUpdate IgnoreOnUpdateMatchedAndOneNotConditionNames Online Example
BulkSynchronize IgnoreOnSynchronizeMatchedAndOneNotConditionNames Online Example

🏁 Conclusion

Using MatchedAndOneNotCondition option in Entity Framework Extensions with EF Core ensures that updates only happen when at least one important value is different between source and destination.

You can choose:

  • Expression-based include β†’ [Action]MatchedAndOneNotConditionExpression
  • Name-based include β†’ [Action]MatchedAndOneNotConditionNames
  • Expression-based exclude β†’ IgnoreOn[Action]MatchedAndOneNotConditionExpression
  • Name-based exclude β†’ IgnoreOn[Action]MatchedAndOneNotConditionNames

By using MatchedAndOneNotCondition in your bulk operations:

  • Skip redundant updates when values are identical
  • Focus updates only on fields that matter
  • Keep imports and synchronizations faster and more predictable

Column Options

Coalesce Options

Matched Options

Delete Matched Options


Last updated: 2025-08-17
Author: