当对Int字段使用Contains时,动态Linq失败 [英] Dynamic Linq failing when using Contains against Int Field

查看:443
本文介绍了当对Int字段使用Contains时,动态Linq失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Entity Frameworks 4.1.0.0和MySQL.Data.Entity 6.5.4.0,当我尝试生成一系列整数的动态查询时,出现以下错误:

I'm using Entity Frameworks 4.1.0.0 and MySQL.Data.Entity 6.5.4.0 and when I try and generate a dynamic query for a range of integers, I get an error of:

类型'Int32'中不存在适用的方法'包含'

No applicable method 'Contains' exists in type 'Int32'

当使用类似的结构检查Strings ..时,这似乎很好用,但是我想扩展它以支持我数据中的其他db字段.

This seems to work fine when using a similar structure to check against Strings..but I want to expand this to support the other db fields I have in my data.

代码示例:

        int[] ids = new int[] { 1, 3, 4 };

        IQueryable<entityname> list = db.tablename.Where("Id.Contains(@0)", ids);

我已将Dynamic.cs添加到我的项目中,并随后添加了 http ://blog.walteralmeida.com/2010/05/advanced-linq-dynamic-linq-library-add-support-for-contains-extension-.html 但是使用Nuget加载的Dynamic I并没有什么区别.

I have added in the Dynamic.cs to my project and followed along with http://blog.walteralmeida.com/2010/05/advanced-linq-dynamic-linq-library-add-support-for-contains-extension-.html but there has been no difference then using the Dynamic I loaded via Nuget.

先谢谢您.

推荐答案

语法略有不同:

IQueryable<entityname> list = db.tablename.Where("@0.Contains(outerIt.Id)", ids);

按照您引用的链接.

这篇关于当对Int字段使用Contains时,动态Linq失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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