从视图添加创建列表时出错

时间:2019-07-18 15:17:07

标签: c# linq

LINQ to Entities无法识别方法'System.String [] Split(Char [])',并且该方法无法转换为商店表达式。

我正在尝试将字符串转换为数组的int。

public class EmpFields2WithGroup
{
    public int EmpID { get; set; }
    public string Name { get; set; }
    public string Cell { get; set; }
    public List<int> grpID { get; set; }   
}


List<EmpFields2WithGroup> Emp = new List<EmpFields2WithGroup>();
Emp = db.EmpGrpViews.Select(x => new EmpFields2WithGroup { EmpID = x.ID, Name = x.Name, Cell = x.Cell, grpID = x.GroupIds.Split(',').Select(int.Parse).ToList()}).ToList();

1 个答案:

答案 0 :(得分:0)

foreach(db.EmpGrpViews中的可变项)             {                 清单grp = item.GroupIds!= null吗? item.GroupIds.Split(',')。Select(y => Int32.Parse(y))。ToList():new List();

            Emp.Add(new EmpFields2WithGroup
            {
                EmpID = item.ID,
                Name = item.Name,
                Cell = item.Cell,
                grpID = grp

            });
        }