Thinktecture.EntityFrameworkCore icon indicating copy to clipboard operation
Thinktecture.EntityFrameworkCore copied to clipboard

Thinktecture.EntityFrameworkCore.BulkOperations throws exception when excluding properties

Open herascu opened this issue 2 months ago • 1 comments

When trying to set the argument to exclude properties on BulkInsert, this exception gets thrown: Complex projections are not supported. Current expression: value(Program+<>c__DisplayClass0_0).propertiesToExclude at Thinktecture.BulkOperationsExpressionExtensions.ExtractMember(ParameterExpression paramExpression, MemberExpression memberAccess) at Thinktecture.BulkOperationsExpressionExtensions.ExtractMembers(List1 members, ParameterExpression paramExpression, Expression body) at Thinktecture.BulkOperationsExpressionExtensions.ExtractMembers[T](Expression1 projection) at Thinktecture.EntityFrameworkCore.BulkOperations.IEntityPropertiesProvider.Exclude[T](Expression`1 projection)

Sample code to replicate - simple C# console app with latest EF Core 8 and SQL Server 2019: var entities = new List<DataTable>(); Expression<Func<DataTable, object>> propertiesToExclude = p => p.RowDateTime; var propertiesToInsertValue = IEntityPropertiesProvider.Exclude<DataTable>(_ => propertiesToExclude); var options = new SqlServerBulkInsertOptions { PropertiesToInsert =propertiesToInsertValue, EnableStreaming = true, BulkCopyTimeout = TimeSpan.FromMinutes(5) }; await DbContext.BulkInsertAsync(entities, options);

public class DataTable { public int Id { get; set; } public string Name { get; set; } public DateTime RowDateTime { get; set; } }

herascu avatar Apr 25 '24 20:04 herascu