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

InsertOrUpdate方法唯一索引bug #1768

Open
MoDao1990217 opened this issue Apr 1, 2024 · 2 comments
Open

InsertOrUpdate方法唯一索引bug #1768

MoDao1990217 opened this issue Apr 1, 2024 · 2 comments

Comments

@MoDao1990217
Copy link

MoDao1990217 commented Apr 1, 2024

问题描述及重现代码:

InsertOrUpdate()
.SetSource(data)
.ExecuteAffrowsAsync();
在执行时,似乎是以主键为主,主键存在时执行更新,不存在时,执行插入。当表中除了主键外,还有唯一索引时,唯一索引存在时,则不会执行更新,而是直接报错,报索引冲突。

SetSource的重载方法,指定临时主键仅对 SqlServer/PostgreSQL/Firebird/达梦/南大通用/金仓/神通 有效

而InsertOrUpdate()
.SetSource(data).ExecuteMySqlBulkCopy()
则不存在此问题,唯一索引存在时,也会执行更新,不存在时,也会执行插入。

InsertOrUpdate<T>()
                        .SetSource(data)
                        .ExecuteAffrowsAsync();

数据库版本

mysql 5.7

安装的Nuget包

各版本都有此问题

.net framework/. net core? 及具体版本

net core6-net core8

@2881099
Copy link
Collaborator

2881099 commented Apr 1, 2024

mysql原生sql指定字段插入或更新

@MoDao1990217
Copy link
Author

mysql原生sql指定字段插入或更新

嗯,目前是这样处理的。

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

No branches or pull requests

2 participants