I have the following an entity I want to search on.. how can I combine two fields to get the correct input..
something like this
var personnels = dbContext.Set<Personnel>()
.Where(p =>
(p.FirstName + ' ' + p.Surname).Contains("John Smith")
);
When I do that it says
Unable to create a constant value of type 'System.Object'. Only primitive types or enumeration types are supported in this context.
This is the code I am trying to fix
var personnels = dbContext.Set<Domain.Entities.App.Personnel>().Where(p =>
((p.GivenName + p.Surname).Contains(criteria.PersonnelName) || String.IsNullOrEmpty(criteria.PersonnelName))
&& (p.PersonnelRoleId == criteria.PersonnelRoleId || (criteria.PersonnelRoleId ?? 0) == 0)
&& (((criteria.ActiveOnly && (p.ActiveFlag)) || (criteria.ActiveOnly == false)))).AsEnumerable();
The code works, but it only works if the criteria is johnsmith not john smith..
so the line is this
(p.GivenName + p.Surname).Contains(criteria.PersonnelName)
how can I get a space in there
(p.GivenName + ' ' + p.Surname).Contains(criteria.PersonnelName)
doesn't work