Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BulkMergeAsync ignores columns with default values in generated INSERT #813

Open
bengavin opened this issue Nov 6, 2024 · 4 comments
Open
Assignees

Comments

@bengavin
Copy link

bengavin commented Nov 6, 2024

1. Description

When generating the MERGE statement, columns which have an EFCore fluent configured default value are ignored when generating the INSERT portion of the SQL statement. They are included in the staging table and in the UPDATE portion of the statement.

2. Exception

N/A

3. Fiddle or Project

Not available at this time, I may have time to put one together later.

4. Any further technical details

Removing the 'HasDefaultValue(...)' configuration on the properties restores the expected behavior. I would expect that, if a database default value was to be returned, it would only be used/returned in the case where the source property on the entity being saved was NULL.

NOTE: This behavior does -not- happen when using BulkSaveChangesAsync

Further technical details

  • EF version: [EF Core v8.0.10]
  • EF Plus version: [EF Plus Core v8.103.4]
  • Database Server version: [Azure SQL Server]
  • Database Provider version (NuGet): [Microsoft.Data.SqlClient v5.1.2]
@bengavin bengavin changed the title BulkMergeAsync ignores columns with duplicate values in generated INSERT BulkMergeAsync ignores columns with default values in generated INSERT Nov 6, 2024
@JonathanMagnan JonathanMagnan self-assigned this Nov 6, 2024
@JonathanMagnan
Copy link
Member

Hello @bengavin ,

That's currently the default behavior. Properties with default values are always ignored by default.

However, you can choose which behavior you want with the option ExplicitValueResolutionMode

By using this following options options.ExplicitValueResolutionMode = Z.EntityFramework.Extensions.ExplicitValueResolutionMode.AlwaysKeepValueOnInsert; now values will always be inserted in the Insert part of the BulkMerge

You can see an online example using this option here

At this moment, only the BulkInsert supports hybrid cases when some entities have value explicitly set and some don't through the SmartDefaultValueOnBulkInsert and SmartPartialResolutionOnBulkInsert mode.

Let me know if that answer correctly to your question.

Best Regards,

Jon

@JonathanMagnan
Copy link
Member

Hello @bengavin,

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

Let me know if you have any questions.

Best regards,
Jon

@bengavin
Copy link
Author

bengavin commented Nov 8, 2024

Thanks @JonathanMagnan - that gets us around the current issue for the moment, is there a plan to implement the smart defaults approach in the merge operation so it functions like the bulk insert?

@JonathanMagnan
Copy link
Member

Hello @bengavin ,

I will talk with my employees next Monday to evaluate the difficulty.

Best Regards,

Jon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants