I have a simple Person View Model
public class PersonViewModel
{
public int ID {get;set;}
public String FirstName {get;set;}
public String LastName {get;set;}
}
The view has three fields
I have this function in my PersonService
which uses an EF6 datacontext which gets injected.
public IQueryable<Person> Search(Expression<Func<Person,bool>> predicate)
{
return dataContext.GetSet<Person>().Where(predicate);
}
Now my MVC Controller actually works with a PersonViewModel class
[HttpPost]
public ActionResult Search(PeopleSearchViewModel model)
{
if (ModelState.IsValid)
{
var listOfPersons= PersonService.Search(
//map viewmodel to model and search here)
//return the list and render a view etc...not important
}
}
So what I am wondering is whether it is a good idea if I can somehow take the PersonViewModel, create a Func<Person,bool>
predicate and pass it to the PersonService
for search, instead of using automapper to map my view model to domain model ?
Thanks