我有一个关系,项目类别。这种关系是多对多的,所以我有三个表:Project / project_has_category / categories。
我需要选择与某个类别有关系的所有项目(通过它的 id)
项目类
public class Project
{
public int ProjectID { get; set; }
public virtual ICollection<Category> Categories { get; set; }
}
类别类
public class Category
{
public int CategoryID { get; set; }
public string CategoryName { get; set; }
public virtual ICollection<Project> Projects { get; set; }
}
我尝试了以下方法:
[HttpPost]
public ActionResult Projects(string catID, string strSearch)
{
var cats = Adapter.CategoryRepository.Get();
var projects = Adapter.ProjectRepository.Get().Where(x => x.Categories.Contains(catID));
/*also*/
var projects = Adapter.ProjectRepository.Get().Where(x => cats.Contains(catID));
return View(projects);
}
但这给出了错误:
'System.Collections.Generic.ICollection.Contains(LibModels.Category)' 的最佳重载方法匹配有一些无效参数 C:\Users\thomas\Desktop\Freelauncher1005\Freelauncher\Controllers\ProjectController.cs
我究竟做错了什么?