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

While inserting new record through BulkMerge it's not overriding default constraint value #572

Closed
Omprakashkumar21 opened this issue Feb 14, 2024 · 3 comments
Assignees

Comments

@Omprakashkumar21
Copy link

Omprakashkumar21 commented Feb 14, 2024

Description

While inserting new record through BulkMerge it's not overriding default constraint value for a column but it's working fine with update. I am using EFCore 7 and .net 6.

public virtual void InsertOrUpdateRange(IEnumerable<T> entities, bool autoDetectChanges = true)
        {
            _entities.Database.SetCommandTimeout(180);
            _entities.ChangeTracker.AutoDetectChangesEnabled = autoDetectChanges;
            try
            {
                _entities.BulkMerge(entities, options => options.ColumnPrimaryKeyExpression = r => r.Id);
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
            finally
            {
                _entities.ChangeTracker.AutoDetectChangesEnabled = true;
            }
        }
@Omprakashkumar21
Copy link
Author

Example - default value for a Int column is 60 in database, but I am setting it as 1 from UI/Code , but after bulkmerge database is reflecting 60 only while insert but while update it is setting 1

@JonathanMagnan JonathanMagnan self-assigned this Feb 15, 2024
@JonathanMagnan
Copy link
Member

Hello @Omprakashkumar21 ,

See the option ForceValueGeneratedStrategy documentation to understand more about this behavior and how to fix it.

Let me know if that solved your issue.

Best Regards,

Jon

@JonathanMagnan
Copy link
Member

Hello @Omprakashkumar21,

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

Let me know if everything is working as expected.

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