Reputation: 13083
This query actually works but returns new objects with ClientName
set to null
where FirstName or Lastname is null
(any one of the two). How can I get around that? I would like to have an empty string instead of null
in those rows.
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
};
Upvotes: 2
Views: 3894
Reputation: 19765
((client.Firstname ?? "") + " " + (client.Lastname ?? "")).Trim();
Upvotes: 11