0
別のリスト内のリストプロパティをフィルタリングする際に問題があります。 私はLinqを使用しようとしています。他のリスト内のリストをフィルタリングする方法MVC LINQ
私は文書のリストを持っていますが、それぞれには著者のリストがあります。 私は、私が筆者の姓を等しくしたいというビューから取得する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