簡體   English   中英

包含linq的方法在另一個linq中不起作用

[英]Method that contains linq not working inside another linq

我目前正在通過在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.

這應該可以解決問題:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM