linq 多表查询出现‘查询包含对不同数据上下文上所定义项的引用。’

后台:
string[] roles = Roles.GetRolesForUser();
        NNYZgbDataContext nnyzgb = new NNYZgbDataContext();
        aspnetdb.aspnetdbDataContext asp = new aspnetdb.aspnetdbDataContext();
        if (roles.Contains("yuanlingdao") || ShowUserAll())
        {
            return;
        }
        if (roles.Contains("Director") || roles.Contains("Vice-Director") || roles.Contains("secretary"))
        {
            e.Result = from z in nnyzgb.jisgwwwnfaInfo join y in asp.vwczcUsers on z.RecorderUId equals y.UserId where !(bool)z.Inactive && y.dept == ((czc_user)Session["user"]).Department orderby z.RecordDate descending select z;
        }

解决方法:

将红色的代码的nnyzgb.jisgwwwnfaInfo 改为:nnyzgb.jisgwwwnfaInfo.ToList()  ,asp.vwczcUsers改为asp.vwczcUsers.ToList() ;

 就是在表后 加上ToList();

posted @ 2014-03-14 16:31  只求清淡如水  阅读(435)  评论(0编辑  收藏  举报