我試圖將Uint(i_Customer)轉換爲Nullable Int(i_Customer)ID,因爲一個接受空值而另一個ID不支持。 父表是Customer(i_Customer),子表是故障(i_customer)。兩者,我正在加入他們的EF查詢來獲得結果。但有一個nullreferenceexception was unhandled by user code
例外,這是非常令人不安。我如何解決它?Ho在EF查詢中將Uint轉換爲Nullable Int
這裏是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;
}
爲什麼不定義你的i_Customer爲INT? ? – mybirthname
@mybirthname,這是可能的定義它,並在EF查詢中使用它?如果是這樣,怎麼樣?請協助。 –
Convert.ToInt32((int?)cInfo.customers.i_Customer)=>(int?)cInfo.customers.i_Customer –