我有一个不是返回适当的响应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