Status = (deals.Count() == 0 ? "Prospect" : "Client")
The conditional operator is used here.
The conditional operator (? :) returns one of two values depending on the value of the boolean expression.
Edit: You can create such combinations:
Status = (deals.Count() == 0 ? "Prospect" : (deals.Count() == 1 ? "Client" : "Other"))
In this case, you use deals.Count() a lot, so you can save the result in a temporary variable using LINQ syntax let:
var result = (
from contact in db.Contacts
join user in db.Users on contact.CreatedByUserID equals user.UserID
join deal in db.Deals on contact.ContactID equals deal.ContactID into deals
let dealCount = deals.Count()
...
Status = (dealCount == 0 ? "Prospect" : (dealCount == 1 ? "Client" : "Other"))
source
share