我正在尝试将Uint(i_Customer)转换为可空Int(i_Customer)ID,因为一个接受Null值,而另一个ID不支持。
父表是Customer(i_Customer),子表是Fault(i_customer)。两者,我都将它们加入EF查询中以获取结果。但是,有一个nullreferenceexception was unhandled by user code
异常非常令人不安。我该如何解决?
这是EF查询:
if (servicelevel == 3)
{
result = (from s in res
join cInfo in custInfo on
s.fault.i_customer equals Convert.ToInt32((int?)cInfo.customers.i_Customer)
where (s.fault.resolved == null) || (s.tasks.assignedto == agent)
orderby s.fault.ispriority descending, s.fault.logtime ascending
select new ActiveFaultResult()
{ Company_Name = cInfo.customers.Company_Name,
//replies = replies,
idFaults = s.fault.idFaults,
hashvalue = s.fault.hashvalue,
responsible = s.fault.responsible,
logtime = s.fault.logtime,
isinternal = s.fault.isinternal,
ispriority = s.fault.ispriority
}).ToList<ActiveFaultResult>();
// var limitresult = result.Take(50);
return result;
}
最佳答案
普通演员会做
s.fault.i_customer equals (int?)cInfo.customers.i_Customer
或者试试这个
s.fault.i_customer ?? 0 equals cInfo.customers.i_Customer