插入操作支持InsertIgnore吗? 返回
SqlSugar
沟通中
2
337
悬赏:0 飞吻
我现在的代码是这样,插入之前先查询一遍,如果有则不插入,但是会影响性能
// 写前查询:同一 (biz_id, event_type, data_hash) 已存在则跳过,确保幂等
var existing = await _db.Queryable<OutboxEvent>()
.Where(e => e.BizId == outboxEvent.BizId)
.Where(e => e.EventType == outboxEvent.EventType)
.Where(e => e.DataHash == outboxEvent.DataHash)
.FirstAsync(); if (existing != null)
{ return false;
} await _db.Insertable(outboxEvent).ExecuteCommandAsync(); return true;有没有更好的写法?
热忱回答(2)
-
fate sta VIP0
1周前部分库插入支支持
.IgnoreInsertError()
0 回复 -
SA VIP0
1周前@fate sta:哪些数据库支持这个特性呢
0 回复