EntityHistoryHelper.ShouldSavePropertyHistory 更新记录时抛出 null 异常
EntityHistoryHelper.ShouldSavePropertyHistory throws null exception when updating record
使用 MVC jQuery、.NET Core、ABP v3.5.0。
实体历史已启用:Configuration.EntityHistory.IsEnabled = true;
我使用 t-sql 将一些数据直接插入到 table 中。
如果我随后尝试通过网络应用程序更新其中一条记录,我会看到抛出的异常:
System.NullReferenceException: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at Abp.EntityHistory.EntityHistoryHelper.ShouldSavePropertyHistory(PropertyEntry propertyEntry, Boolean defaultValue) in D:\Github\aspnetboilerplate\src\Abp.ZeroCore.EntityFrameworkCore\EntityHistory\EntityHistoryHelper.cs:line 292
at Abp.EntityHistory.EntityHistoryHelper.GetPropertyChanges(EntityEntry entityEntry) in D:\Github\aspnetboilerplate\src\Abp.ZeroCore.EntityFrameworkCore\EntityHistory\EntityHistoryHelper.cs:line 210
at Abp.EntityHistory.EntityHistoryHelper.CreateEntityChangeInfo(EntityEntry entityEntry) in D:\Github\aspnetboilerplate\src\Abp.ZeroCore.EntityFrameworkCore\EntityHistory\EntityHistoryHelper.cs:line 160
at Abp.EntityHistory.EntityHistoryHelper.CreateEntityChangeSet(ICollection`1 entityEntries) in D:\Github\aspnetboilerplate\src\Abp.ZeroCore.EntityFrameworkCore\EntityHistory\EntityHistoryHelper.cs:line 95
at Abp.Zero.EntityFrameworkCore.AbpZeroCommonDbContext`3.<SaveChangesAsync>d__98.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
我禁用了实体历史并删除了实体历史选择器,更新现在再次对使用 t-sql.
直接插入 table 的记录起作用
Configuration.EntityHistory.IsEnabled = false;
//Configuration.EntityHistory.Selectors.Add(
// new NamedTypeSelector(
// "Abp.AuditedEntity",
// type => typeof(IAudited).IsAssignableFrom(type)
// )
//);
实体历史功能是否依赖于必须通过网络应用程序插入的数据?
Is the Entity History feature dependent upon the data having to be inserted via the web app?
没有
这已在 ABP v3.6.0 中修复:#3314
As the documentation says PropertyInfo
can be null for shadow properties or properties mapped directly to fields.
本质上,这涉及 null
签入 EntityHistoryHelper.cs:
// if (propertyInfo.IsDefined(typeof(DisableAuditingAttribute), true))
if (propertyInfo != null &&
propertyInfo.IsDefined(typeof(DisableAuditingAttribute), true))
使用 MVC jQuery、.NET Core、ABP v3.5.0。
实体历史已启用:Configuration.EntityHistory.IsEnabled = true;
我使用 t-sql 将一些数据直接插入到 table 中。 如果我随后尝试通过网络应用程序更新其中一条记录,我会看到抛出的异常:
System.NullReferenceException: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at Abp.EntityHistory.EntityHistoryHelper.ShouldSavePropertyHistory(PropertyEntry propertyEntry, Boolean defaultValue) in D:\Github\aspnetboilerplate\src\Abp.ZeroCore.EntityFrameworkCore\EntityHistory\EntityHistoryHelper.cs:line 292
at Abp.EntityHistory.EntityHistoryHelper.GetPropertyChanges(EntityEntry entityEntry) in D:\Github\aspnetboilerplate\src\Abp.ZeroCore.EntityFrameworkCore\EntityHistory\EntityHistoryHelper.cs:line 210
at Abp.EntityHistory.EntityHistoryHelper.CreateEntityChangeInfo(EntityEntry entityEntry) in D:\Github\aspnetboilerplate\src\Abp.ZeroCore.EntityFrameworkCore\EntityHistory\EntityHistoryHelper.cs:line 160
at Abp.EntityHistory.EntityHistoryHelper.CreateEntityChangeSet(ICollection`1 entityEntries) in D:\Github\aspnetboilerplate\src\Abp.ZeroCore.EntityFrameworkCore\EntityHistory\EntityHistoryHelper.cs:line 95
at Abp.Zero.EntityFrameworkCore.AbpZeroCommonDbContext`3.<SaveChangesAsync>d__98.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
我禁用了实体历史并删除了实体历史选择器,更新现在再次对使用 t-sql.
直接插入 table 的记录起作用Configuration.EntityHistory.IsEnabled = false;
//Configuration.EntityHistory.Selectors.Add(
// new NamedTypeSelector(
// "Abp.AuditedEntity",
// type => typeof(IAudited).IsAssignableFrom(type)
// )
//);
实体历史功能是否依赖于必须通过网络应用程序插入的数据?
Is the Entity History feature dependent upon the data having to be inserted via the web app?
没有
这已在 ABP v3.6.0 中修复:#3314
As the documentation says
PropertyInfo
can be null for shadow properties or properties mapped directly to fields.
本质上,这涉及 null
签入 EntityHistoryHelper.cs:
// if (propertyInfo.IsDefined(typeof(DisableAuditingAttribute), true))
if (propertyInfo != null &&
propertyInfo.IsDefined(typeof(DisableAuditingAttribute), true))