此查询实际上有效但返回ClientName
设置为null
的新对象,其中FirstName或Lastname为null
(两者中的任何一个)。我怎么能绕过那个?我希望在这些行中有一个空字符串而不是null
。
var clients =
from client in _repository.GetAll()
where (client.Firstname.StartsWith(query) || client.Lastname.StartsWith(query))
select new
{
ClientName = (client.Firstname + " " + client.Lastname).Trim(),
client.Firstname,
client.Lastname,
client.Address1,
client.Address2,
client.client_id,
client.PrettyId,
client.PostCode.postalcode,
client.PostCode.postname
};
答案 0 :(得分:10)
((client.Firstname ?? "") + " " + (client.Lastname ?? "")).Trim();