这是我得到的错误。 这是一种搜索方法。
错误CS1929' SiteLocation'不包含的定义 '包含'和最好的扩展方法重载 ' Queryable.Contains(IQueryable,string)'需要一个 接收器类型' IQueryable'
public ActionResult Index(string projectname)
{
var projects = db.Projects.Include(p => p.Engineer).Include(p =>
p.SiteLocation);
var a = from p in db.Projects.Include(p => p.Engineer).Include(p =>
p.SiteLocation)
select p;
if (!String.IsNullOrEmpty(projectname))
{
//NumberMCP = c.NumberMCP,
//Engineer = c.Engineer,
//Plink = c.Plink,
a = a.Where(c => c.SiteLocation.Contains(projectname));
a = a.Where(c => c.NumberMCP.Contains(projectname));
a = a.Where(c => c.nameProject.Contains(projectname));
//Ptype = c.Ptype,
// Pyear = c.Pyear,
// SiteLocationID = c.SiteLocationID
}
return View(a.ToList());
}
我认为我的问题可能是这样的:iqueryable将int转换为字符串
答案 0 :(得分:0)
问题:调用INT而不是String
解决: 如果需要,转换类型ToString
a = a.Where(c => c.NumberMCP.Contains(projectname)
|| c.nameProject.Contains(projectname)
|| c.Engineer.ToString().Contains(projectname)
|| c.Plink.Contains(projectname)
|| c.Pyear.ToString().Contains(projectname)
|| c.SiteLocation.ToString().Contains(projectname)
|| c.Ptype.Contains(projectname)