包含linq无法在另一个linq内工作的方法

时间:2015-01-08 06:01:14

标签: c# linq entity entity-framework-6

我目前正在通过调用linq中的方法来解决这个问题:

var entity=GetCustomers(false).Where(a => GetListCompcd(userlinkcd, rolecd).Any(b => b == a.comp_cd));

GetListCompcd方法:

private List<string> GetListCompcd(string userlinkcd, string rolecd)
    {
        List<string> listcompcd = new List<string>();
        if (rolecd == GeneralConst.L_ROLE_AGENT_CD)
        {
            listcompcd.Union(_unitOfWork.Repository<CONTACT>().Query().Filter(a => a.agent_cd == userlinkcd).Get().Select(a => a.comp_cd).ToList());
            listcompcd.Union(_unitOfWork.Repository<AGENT_2D>().Query().Filter(a => a.agent_cd == userlinkcd).Get().Select(a => a.comp_cd).ToList());
        }
        else if (rolecd == GeneralConst.L_ROLE_CGROUP_CD)
        { listcompcd.AddRange(_unitOfWork.Repository<CONTACT>().Query().Filter(a => a.agent_cd == userlinkcd).Get().Select(a => a.comp_cd).ToList()); }
        return listcompcd;
    }

此代码有错误说

LINQ to Entities does not recognize the method 'System.Collections.Generic.List`1[System.String] GetListCompcd(System.String, System.String)' method, and this method cannot be translated into a store expression.

1 个答案:

答案 0 :(得分:-1)

这应该可以解决问题:

var entity=GetCustomers(false).Where(a => GetListCompcd(userlinkcd, rolecd).Contains(a.comp_cd));