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

更新失败,没报错 但是更新后数据依然是旧的 #1856

Open
ClementeGao opened this issue Jul 10, 2024 · 1 comment
Open

更新失败,没报错 但是更新后数据依然是旧的 #1856

ClementeGao opened this issue Jul 10, 2024 · 1 comment

Comments

@ClementeGao
Copy link

ClementeGao commented Jul 10, 2024

问题描述及重现代码:

当执行完以下代码后,数据库的数据没更新,也没报错

var entitis = await _freeSql.Select<PositionGreetingConfigDo>();
var updateCofigs = new List<PositionGreetingConfigDo>();
var configEntity = entitis.First(x => x.positionGreetingConfigId == item.positionGreetingConfigId);
 configEntity.greetCount = item.greetingCount;
 configEntity.triggerTime = item.triggerTime;
updateCofigs.Add(configEntity);
using (var unitOfWork = _freeSql.CreateUnitOfWork())
{
var repo = unitOfWork.GetRepository<PositionGreetingConfigDo>();
//更新
if (updateCofigs.Any())
{
    repo.Attach(updateCofigs);
    var r = repo.Update(updateCofigs);
      unitOfWork.Commit();
}
}

数据库版本

sqlserver 12

安装的Nuget包

FreeSql 3.2.832

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

.netcore3.1

@2881099
Copy link
Collaborator

2881099 commented Jul 10, 2024

repo.Attach 不是这样用的,repo查询出来的记录,才适合用 repo.Update

如果记录来自是json,可以用 repo.Where(a=> items.Any(i => i.Id == a.Id)).ToList()

再 repo.Update(items),建议看文档了解仓储的机制。

也可以直接 repo.UpdateDiy.SetSource(items).ExecuteAffrows() 更新所有字段,这个API对应 fsql.Update修改文档。

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