SqlSugar Updateable 集合参数传一条导致sql没有where条件bug

批量更新的代码:

DSFADb.Updateable<DSFSchedule>(tempList)
.UpdateColumns(d => new string[] {d.Posting Category, d.IsDelete })
.Where(d => d.EST ACT != "est")
.WhereColumns(new string[] { "ContractNo","paymentDate"})
.ExecuteCommand();

其中tempList的count>1的时候生成的SQL如下:

tempListcount=1的时候,生成的SQL如下:

 这个BUG直接导致条件删除变成了批量删除。

目前的解决办法只能是判断list.count==1的时候,随便再加一条假数据进去,具体原因不清楚为什么会造成这个,不知道sqlsugar官网有没有什么方案

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为您封装一个 SqlSugar 的 Repository 工厂类,方便您在项目中使用。以下是代码示例: ```csharp using SqlSugar; public interface IRepository<T> where T : class, new() { ISugarQueryable<T> Queryable { get; } T GetById(object id); bool Insert(T entity); bool Update(T entity); bool Delete(T entity); } public class Repository<T> : IRepository<T> where T : class, new() { private readonly SqlSugarClient _db; public Repository(SqlSugarClient db) { _db = db; } public ISugarQueryable<T> Queryable => _db.Queryable<T>(); public T GetById(object id) { return _db.Queryable<T>().InSingle(id); } public bool Insert(T entity) { return _db.Insertable(entity).ExecuteCommand() > 0; } public bool Update(T entity) { return _db.Updateable(entity).ExecuteCommand() > 0; } public bool Delete(T entity) { return _db.Deleteable(entity).ExecuteCommand() > 0; } } public class RepositoryFactory { private readonly SqlSugarClient _db; public RepositoryFactory(string connectionString) { _db = new SqlSugarClient(new ConnectionConfig { ConnectionString = connectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true }); } public IRepository<T> GetRepository<T>() where T : class, new() { return new Repository<T>(_db); } } ``` 使用方法如下: ```csharp // 创建 Repository 工厂类 var factory = new RepositoryFactory("your_connection_string"); // 获取 Repository 实例 var userRepository = factory.GetRepository<User>(); // 使用 Repository 实例 var userList = userRepository.Queryable.Where(u => u.Age > 18).ToList(); var user = userRepository.GetById(1); userRepository.Insert(new User { Name = "张三", Age = 20 }); userRepository.Update(new User { Id = 1, Name = "李四", Age = 21 }); userRepository.Delete(new User { Id = 1 }); ``` 以上代码示例中,我们封装了一个 `IRepository` 接口,定义了一些基本的增删改查方法,同时还提供了 `Queryable` 属性,方便您使用 SqlSugar 的链式查询语法。`Repository` 类实现了 `IRepository` 接口,使用 SqlSugar 来执行数据库操作。`RepositoryFactory` 类则是一个工厂类,用于创建 `IRepository` 接口的实例。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值