我有一個不是返回適當的響應LINQ表達式正確
var query = from quote in db.Quotes
where quote.QuoteStatus == "Estimating" || quote.QuoteStatus == "Rejected"
from emp in db.Employees
where emp.EmployeeID == quote.EmployeeID
orderby quote.QuoteID descending
select new
{
quote.QuoteID,
quote.DateDue,
Company = quote.Company.CompanyName,
Attachments = quote.Attachments.Count,
Employee = emp.FullName,
Estimator = (quote.EstimatorID != null && quote.EstimatorID != String.Empty)
? db.Employees.Single (c => c.EmployeeID == quote.EstimatorID).FullName
: "Unassigned",
Status = quote.QuoteStatus, Priority = quote.Priority
};
問題如下LINQ表達式在於Estimator = (quote.EstimatorID != null && quote.EstimatorID != String.Empty) ? db.Employees.Single(c => c.EmployeeID == quote.EstimatorID).FullName : "Unassigned"
部分。
我從來沒有得到它評價爲「未分配」,在那些應該是,它只是返回null
。我寫錯了嗎?
有一個函數:'string.IsNullOrEmpty' http://msdn.microsoft.com/en-us/library/system.string.isnullorempty.aspx – 2010-04-21 22:58:42
是否quote.Estimator評估爲null或String .Empty'? – 2010-04-21 23:02:49
是的,偶爾會。這是我繼承的舊數據庫。 – WedTM 2010-04-21 23:04:02