Fix complex property update in ON CONFLICT clause#89
Conversation
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where complex property updates were not working correctly in ON CONFLICT clauses during bulk insert operations. The issue was that the expression parser only checked one level of member access, failing to properly identify the root parameter for nested complex property expressions.
Changes:
- Added
GetRootParameter()helper method to traverse nestedMemberExpressionchains and find the root parameter - Modified parameter resolution logic in
ToSqlExpression()to use the new helper for proper handling of complex property access - Added comprehensive test coverage for complex property updates in merge operations with and without WHERE clauses
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| SqlDialectBuilder.cs | Added GetRootParameter() method to traverse expression trees and fixed parameter identification for complex properties in UPDATE/WHERE expressions |
| MergeTestsBase.cs | Added two test methods to verify complex property updates work correctly in merge operations, including scenarios with WHERE conditions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot it does not work (error : Property OwnedComplexType not found in entity type PhenX.EntityFrameworkCore.BulkInsert.Tests.DbContext.TestEntityWithComplexType.) with a test like this : |
…NFLICT Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
Fixed in 43b45ce. The issue was that when using nested Added |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Changes Made
1. Handle nested MemberExpression for complex property access
Added
GetRootParameter()helper to traverse nested expression chains for complex property access in WHERE clauses.2. Handle nested MemberInitExpression for complex property assignments
Added
GetUpdatesFromMemberInit()helper method to properly handle Update expressions with nested object initialization for complex properties. The method is truly recursive to support arbitrary nesting levels.Example supported expression:
Tests Added
InsertEntities_WithComplexType_UpdateAll- Tests updating all columns including complex propertiesInsertEntities_WithComplexType_UpdateWithWhere- Tests complex property access in WHERE clauseInsertEntities_WithComplexType_UpdateComplexPropertyConditionally- Tests nested MemberInitExpression for complex property assignmentOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.