每当我在查询中使用CombinedResultList时,尝试初始化它时都会得到一个空引用异常。如果我不在其下面的查询中使用它,它将正常工作。我的查询是否存在引起空引用的问题?我只是想找回在CombinedResultList中包含优惠券ID的所有行
var combinedResultList = visionLines.Where(line => line != null).SelectMany(line => line.VisionResults).Distinct().ToList(); //Get Null reference exception here
eventsFromDb = (from e in db.Events //If I comment out this query the above statement works and no longer throws the null reference exception
where (combinedResultList.Select(result => result.CouponId)).Contains(e.CouponIdentifier)
&& e.ExpiryDate >= _minExpiryDate
select new EventDataTransferObject { EventIdentifier = e.EventIdentifier, DateLastUpdated = e.DateLastUpdated }).ToList();
错误消息:
对象引用未设置为对象的实例。
堆栈跟踪:
在 MyProject.UI.ViewModel.SelectionEditorViewModel.GetEventsByCouponName(String couponName,CancellationToken ct)在 C:\ MyProject.UI \ ViewModel \ SelectionEditorViewModel.cs:第845行