我目前正在通过调用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.
答案 0 :(得分:-1)
这应该可以解决问题:
var entity=GetCustomers(false).Where(a => GetListCompcd(userlinkcd, rolecd).Contains(a.comp_cd));