SqlSugar,Fastest,BulkUpdateAsync 问题反馈 返回

using SqlSugar; namespace SqlSugarTest { internal class Program { static async Task Main(string[] args) { var db = new SqlSugarClient(new SqlSugar.ConnectionConfig() { ConnectionString = "Database=test;Data Source=127.0.0.1;Port=3306;User Id=sa;Password=sasa;AllowLoadLocalInfile=true;", DbType = DbType.MySql, IsAutoCloseConnection = true }); //建表 db.CodeFirst.InitTables<Test>(); //清空表 db.DbMaintenance.TruncateTable<Test>(); var addList = new List<Test>() { new() { Id = 1,Name = "名1", Address = "地址1" }, new() { Id = 2,Name = "名2", Address = "地址2" }, }; //插入测试数据 await db.Insertable(addList).ExecuteCommandAsync(); //修改测试数据 var testList = await db.Queryable<Test>().ToListAsync(); foreach (var item in testList) { item.Name = "新名"; item.Address = "新地址"; item.MSmallPic = new byte[] { 1, 2, 3 }; } var result = await db.Fastest<Test>().BulkUpdateAsync(testList, new string[] { "Id" }, new string[] { "Name", "Address" , "MSmallPic" }); //打印结果 Console.WriteLine($"修改个数:{result}"); Console.WriteLine("用例跑完"); Console.ReadKey(); } /// <summary> /// 测试表 /// </summary> [SugarTable(null, "测试表")] public class Test : BaseEntity { //[SugarColumn(IsPrimaryKey = true, IsIdentity = false)] //public new long Id { get; set; } [SugarColumn(Length = 50)] public string Name { get; set; } /// <summary> /// 图片 /// </summary> [SugarColumn(IsNullable = true)] public byte[]? MSmallPic { get; set; } } public class BaseEntity { [SugarColumn(IsPrimaryKey = true, IsIdentity = false)] public long Id { get; set; } [SugarColumn(Length = 50)] public string Address { get; set; } } } }
问题1:当主键id来自继承的时候,修改数据失败,没有报错。
问题2:当使用Test 中的Id 时,把Name移动导BaseEntity 中,会出现下面的问题,修改的信息乱了。
bug产生和主键id的是否来自继承,和类中有byte[]? 类型的属性 有关系。
热忱回答(7)
-
fate sta VIP0
2周前不要用new,改用虚属性,加重写的方法实现。 试试
0 回复 -
fate sta VIP0
2周前[SugarColumn(IsPrimaryKey = true, IsIdentity = false)]
public virtual long Id { get; set; }
重写
[SugarColumn(IsPrimaryKey = true, IsIdentity = false)]
public override long Id { get; set; }
0 回复 -
QQ6 VIP0
1周前@fate sta:用override 也是一样的。因为我改变了class属性的顺序,所以写入数据的时候,数据是乱的。您可以把这个代码拿出去跑一下,这样子可以更清楚。
反馈的是两个bug。第一个bug,是用继承里面的id,出现的bug。第二个bug,是不用继承的id,调整了class属性的顺序,产生的bug。属性里面一定得有
byte
[]?类型的,才会出现bug。帮忙尽快处理
0 回复 -
fate sta VIP0
1周前实体顺序的问题,byte[]没有用我自个写的文件写入。用的mysqlconnector自带的
0 回复 -
fate sta VIP0
1周前顺序不同导致插入错误。我想办法处理一下。
0 回复 -
fate sta VIP0
1周前SqlSugarCore 5.1.4.189-preview21
更新到预览版本21已修复
0 回复 -
QQ6 VIP0
1周前@fate sta:还有一个,主键用的是继承class里面的,无法修改成功的问题。
0 回复