LINQ Expression not evaluating correctly
Posted
by WedTM
on Stack Overflow
See other posts from Stack Overflow
or by WedTM
Published on 2010-04-21T22:52:52Z
Indexed on
2010/04/21
23:03 UTC
Read the original article
Hit count: 505
I have the following LINQ expression that's not returning the appropriate response
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
};
The problem lies in the Estimator = (quote.EstimatorID != null && quote.EstimatorID != String.Empty) ? db.Employees.Single(c => c.EmployeeID == quote.EstimatorID).FullName : "Unassigned"
part.
I NEVER get it to evalueate to "Unassigned", on the ones that are supposed to, it just returns null
. Have I written this wrong?
© Stack Overflow or respective owner