Skip to content

Commit 43b45ce

Browse files
CopilotPhenX
andcommitted
Make GetUpdatesFromMemberInit truly recursive for arbitrary nesting
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
1 parent 4dbb7b9 commit 43b45ce

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

src/PhenX.EntityFrameworkCore.BulkInsert/Dialect/SqlDialectBuilder.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ private string ToSqlExpression<TEntity>(DbContext context, TableMetadata table,
413413

414414
/// <summary>
415415
/// Extracts update SQL statements from a MemberInitExpression, handling both simple properties
416-
/// and nested complex property initializations.
416+
/// and nested complex property initializations recursively.
417417
/// </summary>
418418
/// <param name="context">DB context</param>
419419
/// <param name="table">Table metadata</param>
@@ -428,16 +428,15 @@ private IEnumerable<string> GetUpdatesFromMemberInit<T>(DbContext context, Table
428428
// Check if the binding expression is a nested MemberInitExpression (complex property assignment)
429429
if (binding.Expression is MemberInitExpression nestedMemberInit)
430430
{
431-
// Recursively process nested complex property assignments
432-
foreach (var nestedBinding in nestedMemberInit.Bindings.OfType<MemberAssignment>())
431+
// Recursively process nested complex property assignments to handle arbitrary nesting levels
432+
foreach (var update in GetUpdatesFromMemberInit<T>(context, table, nestedMemberInit, lambda))
433433
{
434-
// For complex properties, the column name is the nested property name (e.g., "Code", "Name")
435-
yield return $"{table.GetQuotedColumnName(nestedBinding.Member.Name)} = {ToSqlExpression<T>(context, table, nestedBinding.Expression, lambda)}";
434+
yield return update;
436435
}
437436
}
438437
else
439438
{
440-
// Simple property assignment
439+
// Simple property assignment - the column name is the property name
441440
yield return $"{table.GetQuotedColumnName(binding.Member.Name)} = {ToSqlExpression<T>(context, table, binding.Expression, lambda)}";
442441
}
443442
}

0 commit comments

Comments
 (0)