0

我正在尝试使用谓词生成器通过 MVC3 执行查询。我收到错误

“无法将类型 'System.Boolean' 转换为类型 'System.Object'。LINQ to Entities 仅支持转换实体数据模型原始类型。”

我已通过如下查询

if (!string.IsNullOrEmpty(SearchObj.EmployeeIDSortId.ToString()) && SearchObj.EmployeeIDSortId > 0)
    {

        string[] vals =new string[' ']; 
        if (SearchObj.EmployeeIDSortId == 1)
        {
            vals = new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k","l" };

        }
        else if (SearchObj.EmployeeIDSortId == 2)
        {

            vals = new string[] { "m", "n", "o", "p", "q", "r", "s" };

        }
        else if (SearchObj.EmployeeIDSortId == 3)
        {


            vals = new string[] { "t", "u", "v", "w", "x", "y", "z" };
        }


        employeepredicate =
            employeepredicate.And(emp => emp.EmployeeName.Substring(0, 1).ToLower().Equals(vals.Any()));


         }

你能建议这有什么问题吗,我想这只是由于我的查询 vals.Any()。

谢谢

4

1 回答 1

2

让我作为序言 - 我不熟悉该And方法,但对.Equals(vals.Any())我来说看起来不正确。所以,我假设这And需要一个返回布尔值的函数。您真正要查找的是确定员工姓名中的第一个字符是否包含在 vals 数组中:

employeepredicate = employeepredicate.And( emp => vals.Contains(emp.EmployeeName.Substring(0, 1).ToLower()));

于 2012-05-20T12:58:17.967 回答