请问下大家有没遇到EF调用GetValidationErrors时出错

请问下大家有没遇到EF调用GetValidationErrors时出错,我知道报错是说未将对象设置为引用对象,但我不明白为什么调用GetValidationErrors时里面报错。错误代码如下:
error message:Object reference not set to an instance of an object., the UniqueReference value is :1334241M01. We will move this file.]
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Data.Entity.Core.Objects.EntityEntry.DetectChangesInProperty(Int32 ordinal, Boolean detectOnlyComplexProperties, Boolean detectOnly)
at System.Data.Entity.Core.Objects.EntityEntry.DetectChangesInProperties(Boolean detectOnlyComplexProperties)
at System.Data.Entity.Core.Objects.ObjectStateManager.DetectChangesInScalarAndComplexProperties(IList1 entries)
at System.Data.Entity.Core.Objects.ObjectStateManager.DetectChanges()
at System.Data.Entity.Core.Objects.ObjectContext.DetectChanges()
at System.Data.Entity.Internal.InternalContext.DetectChanges(Boolean force)
at System.Data.Entity.Internal.InternalContext.GetStateEntries(Func
2 predicate)
at System.Data.Entity.Internal.InternalContext.GetStateEntries()
at System.Data.Entity.Infrastructure.DbChangeTracker.Entries()
at System.Data.Entity.DbContext.GetValidationErrors()
at Ligentia.DataTool.ClientLibraries.OfficeWorks.JobImportShipmentData.getDbError(Ligentix4Entities L4Entities)。
其中getDbError是我自己写的方法。其余都是调用微软的EFContext.GetValidationErrors()时报错了。但在调用GetValidationErrors()方法前,我有判断调用的对象不是为空了,如:
if (l4Entities != null)
{
IEnumerable validationResults =l4Context.GetValidationErrors();
}
请教大家帮帮忙看下为什么啊?谢谢大家

1个回答

System.NullReferenceException: Object reference not set to an instance of an object.

空引用了,debug看一下具体出错在哪一行

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问