0
다른 목록의 목록 속성을 필터링하는 데 문제가 있습니다. Linq를 사용하려고합니다.다른 목록의 목록을 필터링하는 방법 MVC LINQ
문서 목록이 있습니다. 각 목록에는 작성자 목록이 있습니다. 작성자의 성을 같게하는 view에서 얻는 searchString 매개 변수가 있습니다. 클래스 문서의 다른 속성을 사용하여 작업을 수행 할 수 있었지만 목록으로 처리 할 수는 없습니다.
public ActionResult Index(string searchBy,string searchString)
{
db.Documentos.Include(l => l.Pais);
db.Documentos.Include(l => l.Etiquetas);
db.Documentos.Include(l => l.Autores);
var documentos = from m in db.Documentos select m;
if (searchBy=="Titulo"&& !string.IsNullOrEmpty(searchString))
{
documentos = documentos.Where(s => s.Titulo.Contains(searchString));
}
if(searchBy =="Fecha" && !string.IsNullOrEmpty(searchString))
{
documentos = documentos.Where(s => s.Fecha.ToString().Contains(searchString));
}
if(searchBy == "Autor" && !string.IsNullOrEmpty(searchString))
{
documentos = documentos.Where(x => documentos.All(y => y.Autores.All(a => a.Apellido.Contains(searchString))));
// this doesn't return anything, I cant filter with this.
}
return View(documentos.ToList());
}
고맙습니다! 그것은 일했다!! – EmiL
@EmiL 효과가 있다면 다른 사람에게 도움이되도록 수락 된 응답을 표시하고 싶을 것입니다. 왜 대답을 받아들이는 것이 좋은지에 대한 더 많은 정보가 있습니다 : http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – CodingYoshi
나는 몰랐습니다. 정보를 주셔서 감사합니다 :) – EmiL