[英]entity framework LIKE query
I am using EF4.1 with MySql and unable to get LIKE query working. 我使用EF4.1与MySql,无法使LIKE查询工作。 I want to get list of products where name like app
我想得到像app这样的名字的产品列表
.Where(p=>p.Name.Contains("app") returns only one product with name Apple. The generated SQL contains LOCATE operator in place of LIKE '%app%' .Where(p => p.Name.Contains(“app”)只返回一个名为Apple的产品。生成的SQL包含LOCATE运算符代替LIKE'%app%'
I tried executing sql command using SqlQuery("select * from product where name like '%@p0%'", "app") but to no avail. 我尝试使用SqlQuery执行sql命令(“选择*来自产品,其中名称如'%@ p0%'”,“app”)但无济于事。 It does not retrun any products.
它不会退回任何产品。
Could some please suggest how can I write LIKE for MySql db. 有些人可以建议我如何为MySql db编写LIKE。 Thanks
谢谢
I do not know EF (yo no hablo Microsoft), but I bet that the wildcards on your literal are interfering with the parameter replacement. 我不知道EF(哟没有hablo Microsoft),但我敢打赌,你文字上的通配符会干扰参数替换。
If you try something like the following, does it help? 如果您尝试以下内容,它会有帮助吗?
SqlQuery("select * from product where name like concat('%',@p0,'%')", "app")
Is "@p0" the parameter? “@ p0”是参数吗? I assume so.
我这么认为。
Also, try: 另外,尝试:
SqlQuery("select * from product where name like '@p0'", "%app%")
Also: 也:
SqlQuery("select * from product where name like @p0", "'%app%'")
I bet one of these will work. 我打赌其中一个会起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.