EntityFramework-Extensions icon indicating copy to clipboard operation
EntityFramework-Extensions copied to clipboard

BulkInsertOptimizedAsync does not recognize EF Core shadow properties - Missing Column error

Open Valem opened this issue 4 weeks ago • 2 comments

Description

We are implementing a delta tracking feature for master data replication where we want to store a hash of each entity's properties for change detection. We use a shadow property called _Hash (varchar(16)) which is configured on all entity types in our model.

The shadow property is configured via ModelBuilder and works correctly with standard EF Core operations. However, when using BulkInsertOptimizedAsync, we receive the following exception:

System.Exception: An error occured while resolving mapping by name. See the inner exception for details
 ---> System.Exception: Missing Column : _Hash
On entity : Vendor
On Table : [mdb].[Vendor]
   at Z.BulkOperations.BulkOperation...

The column _Hash does exist in the database table (confirmed via migration). The issue is that BulkInsertOptimizedAsync appears to use CLR reflection to identify columns rather than EF Core's metadata/ChangeTracker, so it doesn't see the shadow property.

Our Setup

Shadow property configuration:

public static ModelBuilder ConfigureDeltaTracking(this ModelBuilder modelBuilder)
{
    foreach (var entityType in modelBuilder.Model.GetEntityTypes())
    {
        if (entityType.ClrType != null && !entityType.IsOwned())
        {
            var entityBuilder = modelBuilder.Entity(entityType.ClrType);

            entityBuilder
                .Property<string>("_Hash")
                .HasColumnType("varchar(16)")
                .IsRequired(false);

            entityBuilder
                .HasIndex("_Hash")
                .IncludeProperties("Id");
        }
    }

    return modelBuilder;
}

Setting the shadow property value before bulk insert:

foreach (var entity in batch)
{
    var hash = _hashGenerator.ComputeHash(entity);
    var entry = localContext.Entry(entity);
    entry.Property("_Hash").CurrentValue = hash;
}

await localContext.BulkInsertOptimizedAsync(batch, cancellationToken);

Expected Behavior

BulkInsertOptimizedAsync should recognize shadow properties configured in EF Core's model and include them in the bulk insert operation, similar to how the regular BulkInsert method handles them (we assume).

Actual Behavior

The operation fails with "Missing Column: _Hash" because the library uses CLR type reflection instead of EF Core's model metadata to discover columns.

Question

Is there a way to make BulkInsertOptimizedAsync recognize and include shadow properties?

Workaround Attempted

We are currently working around this by converting the shadow property to a regular CLR property on an interface (IHashTrackableEntity), but this pollutes our domain model with infrastructure concerns. We would prefer to keep using shadow properties if possible.

Further technical details

  • EF Core version: 8.1.0
  • EF Extensions version: 8.105.0
  • Database Provider: SQL Server (Azure SQL Database)
  • Method used: BulkInsertOptimizedAsync

Thank you for your assistance!

Valem avatar Dec 01 '25 10:12 Valem

Hello @Valem,

Do you think you could create a runnable project that reproduces the issue? It doesn’t need to be your full project, just a new solution with the minimum code required to reproduce the problem.

You can send it in private here: [email protected]

We would like to give you the right solution for how you can achieve this, but my developer wants to make sure he works with a scenario similar to yours.


Just to let you know, this kind of issue with a shadow property is also expected by our library for bulk methods such as BulkInsertOptimized

The main reason is that we don’t use the ChangeTracker for optimization, so our library is usually not aware of shadow values.

We use the EF Core model to know which properties to use, as you are expecting, not reflection.

JonathanMagnan avatar Dec 01 '25 15:12 JonathanMagnan

Hello @Valem,

Since our last conversation, we haven't heard from you.

Let me know if you have any other questions.

Best regards,

Jon

JonathanMagnan avatar Dec 11 '25 14:12 JonathanMagnan

Hello @Valem,

A simple reminder that we are here to assist you.

Don't hesitate to contact us if you need anything.

Best regards,

Jon

JonathanMagnan avatar Dec 22 '25 00:12 JonathanMagnan