【发布时间】:2026-02-09 03:00:02
【问题描述】:
当我尝试检索一些数据时出现此错误。这是我的查询方式
using (_realtyContext = new realtydbEntities())
{
foreach (int yr in years)
{
var standard = (from feest in _realtyContext.FeeStandards
where feest.Year == yr && feest.FeeCategory.CategoryName == "PropertyFee"
select feest).SingleOrDefault();
var chargeItem = (from chrgItem in _realtyContext.PropertyFees
where chrgItem.FeeStandardID == standard.FeeStandardID
&& chrgItem.HousholdId == Householder.HouseholdID
select chrgItem).SingleOrDefault();
this._propertyFees.Add(chargeItem);
this._standards.Add(standard);
}
}
异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例。
错误出现在第二次查询中。(var chargeItem)
此查询引发错误:var chargeItem =...
【问题讨论】:
-
哪一行导致错误?
-
请给你的问题更有意义的话题。
标签: c# .net entity-framework exception-handling linq-to-entities