首页 新闻 会员 周边 捐助

EF 报LINQ to Entities 不支持 LINQ 表达式节点类型“Invoke”,在线求助!!!

0
悬赏园豆:40 [已解决问题] 解决于 2015-03-20 21:53

以下是我的代码片段:

Expression<Func<T_ZhaoBiaoInfo,bool>> whereExpr = PredicateExtensions.True<T_ZhaoBiaoInfo>();
            if (!string.IsNullOrEmpty(category))
            {
                whereExpr = whereExpr.And(t => t.Category == category);
            }

            if (!string.IsNullOrEmpty(region))
            {
                whereExpr = whereExpr.And(t => t.Region == region);
            }

            if (DateTime.TryParse(bcreatedt, out beginCreateDt))
            {
                whereExpr = whereExpr.And(t => t.CreateDateTime >= beginCreateDt);
            }

            if (DateTime.TryParse(ecreatedt, out endCreateDt))
            {
                whereExpr = whereExpr.And(t => t.CreateDateTime <= endCreateDt);
            }

            if (!string.IsNullOrEmpty(zbNo))
            {
                whereExpr = whereExpr.And(t => t.ZBNo == zbNo);
            }

            ZhaoBiaoService zhaoBiaoService = new ZhaoBiaoService();

            var zhaoBiaoInfoList = zhaoBiaoService.FindListByPage(whereExpr, t => new { t.ZBNo, t.Title, t.CreateDateTime, t.Region, t.Category, t.StartDateTime, t.EndDateTime }, t => t.CreateDateTime, 1, aspNetPager.PageSize, pageNo, out recordCount);


以下是调用的分页方法:

public IEnumerable<TResult> FindListByPage<TResult, TKey>(Expression<Func<T, bool>> whereExpr, Expression<Func<T, TResult>> selectExpr, Expression<Func<TResult, TKey>> orderbyExpr, int orderDirection, int pageSize, int pageNo, out int recordCount)
        {
            recordCount = 0;
            var result = zbEntities.CreateObjectSet<T>().Where(whereExpr).Select(selectExpr);
            if (result == null) return null;
            recordCount = result.Count();

            if (pageNo > recordCount) pageNo = recordCount;
            if (pageNo <= 0) pageNo = 1;

            if (recordCount > 0)
            {
                if (recordCount > pageSize)
                {
                    if (orderDirection > 0)
                    {
                        return result.OrderByDescending(orderbyExpr).Skip((pageNo - 1) * pageSize).Take(pageSize).ToList();
                    }
                    else
                    {
                        return result.OrderBy(orderbyExpr).Skip((pageNo - 1) * pageSize).Take(pageSize).ToList();
                    }
                }
                else
                {
                    if (orderDirection > 0)
                    {
                        return result.OrderByDescending(orderbyExpr).ToList();
                    }
                    else
                    {
                        return result.OrderBy(orderbyExpr).ToList();
                    }
                }

            }
            return null;
        }

网上有很多的解决方案,但都不能解决我这个问题,我也不知道如何处理,之前一直用得好好的,现在就是不行,麻烦大家帮忙分析一下,找出问题原因,谢谢!

梦在旅途的主页 梦在旅途 | 初学一级 | 园豆:10
提问于:2015-02-10 14:27
< >
分享
最佳答案
0

http://q.cnblogs.com/q/60724/ 

兄台,答案在此:

收获园豆:40
KingMi | 小虾三级 |园豆:1344 | 2015-02-10 17:20
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册