Wednesday, July 3, 2013

LINQ: filter by two fields concatenation

When you hava an entiy with FirstName and LastName columns, and you need to filter by fullname, a quick solution is to filter by the fields value concatenation:

var agents = from a in DB.Agents
                                 where a.FirstName.Contains(name) ||
                                       a.LastName.Contains(name) ||
                                       String.Concat(a.FirstName, " ", a.LastName).Contains(name)
                                 select a;



No comments: