指定字段更新报错:主键不能更新 版本5.1.4.167 返回
SqlSugar
处理完成
8
227
halajian 发布于2周前
悬赏:0 飞吻
2.1 指定多个字段更新
更新 name,createtime 条件id=11
var result= db.Updateable<Student>() .SetColumns(it => new Student() { Name= "a" ,CreateTime=DateTime.Now}) //类只能在表达示里面不能提取 .Where(it => it.Id == 11) .ExecuteCommand(); //表达式写2列更新2列,其他不会更新 |
热忱回答(8)
-
fate sta VIP02周前
主键不能写到set中。说的很明显了。
还有疑问提供实体类
0 回复 -
halajian VIP02周前
实体类中Id是主键,这个SetColumns里面没有主键更新,Where里是判断条件Id。
0 回复 -
halajian VIP02周前
是不是SetColumns赋值时,必须是值类型?
0 回复 -
halajian VIP02周前
5.1.4.152以前都可以通过,从5.1.4.153开始就会报这个错了
0 回复 -
fate sta VIP02周前
实体类发全,关键看不清楚
0 回复 -
halajian VIP02周前
/// <summary> /// 样品溶液类 /// </summary> [SugarTable("BYSampleSolution")] public class SampleSolution { #region 属性 [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnDescription = "序号ID")] public int Id { get; set; } [SugarColumn(ColumnDescription = "唯一编码")] public string SoleNo { get; set; } [SugarColumn(ColumnDescription = "样品名称")] public string SampleName { get; set; } [SugarColumn(ColumnDescription = "样品编号")] public string SampleNo { get; set; } = string.Empty; [SugarColumn(ColumnDescription = "样品二维码")] public string SampleQRcode { get; set; } = string.Empty; [SugarColumn(ColumnDescription = "样品当前位置")] public string CurrentPos { get; set; } [SugarColumn(ColumnDescription = "样品初始位置")] public string InitPos { get; set; } [SugarColumn(ColumnDescription = "样品当前重量")] public int Weight { get; set; } = 0; [SugarColumn(ColumnDescription = "样品是否能进样")] public bool IsCanMove { get; set; } [SugarColumn(ColumnDescription = "样品显示状态")] public EnumSampleSolutionViewStatus ViewStatus { get; set; } [SugarColumn(ColumnDescription = "样品运动状态")] public EnumSampleSolutionRunningStatus RunningStatus { get; set; } [SugarColumn(ColumnDescription = "样品缓存位置")] public string TempPos { get; set; } = string.Empty; [SugarColumn(ColumnDescription = "样品任务所属列表编号")] public string TaskListNo { get; set; } = GlobalVariable._TASKLISTNO_; [SugarColumn(ColumnDescription = "样品备注信息")] public string Info { get; set; } = string.Empty; [SugarColumn(ColumnDescription = "优先权限值")] public int PriorityAuthority { get; set; } = 0; [SugarColumn(ColumnDescription = "样品添加类型")] public EnumSampleAddType AddType { get; set; } = EnumSampleAddType.HandSampling; [SugarColumn(ColumnDescription = "样品是否需要瓶身识别")] public bool IsNeedBottleScan { get; set; } = false; [SugarColumn(ColumnDescription = "样品是否需要瓶盖识别")] public bool IsNeedCapScan { get; set; } = false; [SugarColumn(ColumnDescription = "样品采样时间")] public string SampleDate { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); [SugarColumn(ColumnDescription = "样品接样时间")] public string ExtendDate { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); [SugarColumn(ColumnDescription = "样品分析时间")] public string TestDate { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); [SugarColumn(ColumnDescription = "样品是否为LIMS创建")] public bool IsLIMSCreated { get; set; } = false; [SugarColumn(IsIgnore = true)] public bool IsNeedWeigh { get; set; } [SugarColumn(IsIgnore = true)] public int CurrentNeedWeight { get; set; } = 100; [SugarColumn(IsIgnore = true)] public bool IsSampleError { get; set; } [SugarColumn(IsIgnore = true)] public bool IsNeedClean { get; set; } [SugarColumn(IsIgnore = true)] public bool IsNeedStir { get; set; } #endregion }
0 回复 -
fate sta VIP02周前
[SugarColumn(IsIgnore =
true
)]
public
int
CurrentNeedWeight {
get
;
set
; } = 100;
这个字段你加了isignore导致 set 失效
0 回复 -
halajian VIP02周前
好的 谢谢
0 回复