2 chgsh 2008 chgsh_2008 于 2014.10.15 11:06 提问

请问下大家有没遇到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个回答

q107770540
q107770540   Ds   Rxr 2014.12.08 10:53

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

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

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!