[Dependency] public IKu<Suifang> Suifangku { get; set; } ... [CatchException()] public ActionResult Index(..., long suifangJibieId = -1) { using (new UnitOfWorkScope()) { ... IQueryable<Suifang> query = Suifangku ; List<SelectListItem> suifangjibies = new List<SelectListItem>(); suifangjibies.Add(new SelectListItem { Text = "不限随访级别", Value = "-1", Selected = (-1 == suifangJibieId), }); ... //正确代码
query = query.Where(m => suifangjibies.Where(x => x.Value != "-1").Select(x => long.Parse(x.Value)).ToList().Contains(m.JibieId));//m.JibieId数据类型为long //错误代码 //query = query.Where(m => suifangjibies.Where(x => x.Value != "-1").Select(x => x.Value).ToList().Contains(m.JibieId.ToString()));//m.JibieId数据类型为long
...
数据库依赖注入查询时,若属性类型是long类型,当你转化为string类型进行Contains(m.JibieId.ToString())条件筛选时,将会报错。见代码段示例。