无法将lambda表达式转换为类型部门

时间:2016-12-31 06:28:19

标签: linq lambda

public static IList<NameValueCore> FindDepartment(string search)
{
    return Repository<Department>
          .Find(p =>( p.Name.Contains(search)) &&  ( p.RegistrationEntityType.Id == ((int)Session["SelectMenu"] == 12 ? 1 : (int)Session["SelectMenu"])))
          .Take(40)
          .ToList()
          .Select(p => new NameValueCore(p.Name, p.Id.ToString()))
          .ToList();
}

此部分生成错误:( p.RegistrationEntityType.Id == ((int)Session["SelectMenu"] == 12 ? 1 : (int)Session["SelectMenu"])

1 个答案:

答案 0 :(得分:0)

在检查Session的操作之前:

public static IList<NameValueCore> FindDepartment(string search)
    {
       int selectMenu = 1;
       if(Session["SelectMenu"]!=null)
       {
          selectMenu=(int)Session["SelectMenu"];
       }

       return Repository<Department>
                          .Find(p =>( p.Name.Contains(search)) &&  ( p.RegistrationEntityType.Id == (selectMenu == 12 ? 1 : selectMenu)))
                          .Take(40)
                          .ToList()
                          .Select(p => new NameValueCore(p.Name, p.Id.ToString()))
                          .ToList();
    }