差异日志功能,如果实体类中的属性有默认值的话,那么调用差异日志功能的时候就会报空指针异常,去掉默认值就没问题 返回

C#论坛 老数据
5 1986
该叫什么 Liye 发布于2020/12/3
悬赏:5 飞吻

下面图片中是一个实体类,UserIds和CheckedUsers是属性名称,我给默认new了一下


image.png

下图是调用的地方,已经加上了EnableDiffLogEvent()

image.png

报错信息:

   at SqlSugar.InsertableProvider`1.<>c__DisplayClass95_2.<GetDiffTable>b__3(EntityColumnInfo it)

   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)

   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)

   at SqlSugar.InsertableProvider`1.GetDiffTable(String sql, Nullable`1 identity)

   at SqlSugar.InsertableProvider`1.After(String sql, Nullable`1 result)

   at SqlSugar.InsertableProvider`1.ExecuteCommand()

   at EAP.Service.GroupManager.Imp.GroupService.Insert(Group group) in C:\Work\Code\eapDev\EAP.Service\GroupManager\Imp\GroupService.cs:line 60


麻烦凯哥看下,是否是我这边代码的写法问题...

热忱回答5

  • 好的我会验证一下

    0 回复
  • Liye Liye VIP0
    2020/12/3

    @fate stay night
    因为比较急,我下午调试了一下,大概就是在这里出错了,具体原因是因为字段上面加了SugarColumn(IsIgnore = true),这样的话EntityColumnInfo的属性DbColumnName就会为空,也是后面导致空指针的原因,在比较的时候我调换了一下顺序,避免可空指针,其他的没做验证,我不知道做得对不对image.png

    0 回复
  • Liye Liye VIP0
    2020/12/3

    @fate stay night

    对了 这个源码是我大概今年年中下载下来的 应该不是最新的 可能行数啥的有点不对

    0 回复
  • @Liye:这个问题是改过了 就是前几天改的,你可以用最新的fremawork版本测一下,CORE版本我还没有同步

    0 回复
  • Liye Liye VIP0
    2020/12/3

    @fate stay night:好的 那到时候还请记得同步到Core版本....我们不用Framework版本了

    0 回复