LinqKit谓词生成器会引发TypeLoadException吗? [英] LinqKit Predicate Builder throws TypeLoadException?

查看:108
本文介绍了LinqKit谓词生成器会引发TypeLoadException吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试执行使用PredicateBuilder动态生成的查询时遇到问题.

I am experiencing a problem while attempting to execute a query that I have built dynamically using PredicateBuilder.

我能够构建查询,但是当执行查询本身时,我得到以下"TypeLoadException" ...

I am able to build the query but when executing the query itself I get the following "TypeLoadException"...

运行时: return context.SearchRecords.AsExpandable().Where(predicate).ToList();

无法从程序集'EntityFramework,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'中加载类型'System.Data.Entity.Infrastructure.IDbAsyncEnumerable'1'.

我已经花了很长时间了,我已经检查了在线示例等,而且我似乎做得很好,所以我希望它能起作用.

I have been pulling my hair out with this for quite a while now, I have checked online examples etc and I seem to be doing everything correctly so I would expect this to work.

private IEnumerable<SearchDto> BuildAndExecuteQuery(string queryString)
    {
        var queryWords = this.GetQueryWordsFromQueryString(queryString);
        using (var context = new AlleyOopSearchContext())
        {
            var predicate = PredicateBuilder.False<SearchDto>();
            foreach (var word in queryWords)
            {
                var temp = word;
                predicate = predicate.Or(p => p.ShotDescription.Contains(temp));
            }

            return context.SearchRecords.AsExpandable().Where(predicate).ToList();
        }
    }

项目使用.NET Framework 4.5构建,并使用Entity Framework 6.

Project is built using .NET Framework 4.5 and uses Entity Framework 6.

提前谢谢!

推荐答案

经过更多调查,我自己找到了答案,结果发现该解决方案中的另一个项目正在引用较新版本的Entity Framework.

After more investigation I found the answer for myself, it turned out that anouther project within the solution was referencing a newer version of Entity Framework.

将所有项目升级到相同版本可以解决此问题.

Upgrading all projects to the same version solved this issue.

这篇关于LinqKit谓词生成器会引发TypeLoadException吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆