Adding Additional Query To Return(view)
I have a ViewModel and I currently return a query where if the movie has employees and they have a role then that movie, actor(s), and role(s) are all returned. Now I want to add a
Solution 1:
I think you should add a property IEnumerable<string> employeeNames
to the view model.
var query =
from m in db.Movies
from me in m.MovieEmployees
where (parameter == 1 && m.Name.Contains(searchString)) ||
(parameter == 2 && me.Employee.Name.Contains(searchString)) ||
(parameter == 3 && me.Role.RoleType.Contains(searchString))
selectnew StarringViewModel
{
employeeID = e.ID,
movieID = m.ID, roleID = r.ID,
movieName = m.Name,
movieDescription = m.Description,
movieReleaseDate = m.ReleaseDate,
employeeBirthdate = me.Employee.Birthday,
employeeName = me.Employee.Name, Role = me.Role.RoleType,
employeeNames = m.MovieEmployees
.Selext(x => x.Employee.Name)
};
(Notice, by the way, that I use navigation properties rather than joins).
You can show the employees by concatenating them:
string.Join(", ", employeeNames)
either in the view, or in a property like EmployeeNamesString
in the view model.
An example of how to do it in the view model:
publicstring EmployeeNamesString
{
get { returnstring.Join(", ", this.employeeNames); }
}
and display EmployeeNamesString
in the view.
Post a Comment for "Adding Additional Query To Return(view)"