我正在使用EF4.1和MySql,无法使LIKE查询正常工作。我想获得名称如app
的产品列表。其中(p => p.Name.Contains(“app”)只返回一个名为Apple的产品。生成的SQL包含LOCATE运算符代替LIKE'%app%'
我尝试使用SqlQuery执行sql命令(“select * from product where name like'%@ p0%'”,“app”)但无济于事。它不会退回任何产品。
有些人可以建议我如何为MySql db编写LIKE。感谢
答案 0 :(得分:0)
我不知道EF(哟没有hablo Microsoft),但我敢打赌,你文字中的通配符会干扰参数替换。
如果您尝试以下内容,是否有帮助?
SqlQuery("select * from product where name like concat('%',@p0,'%')", "app")
“@ p0”是参数吗?我这么认为。
另外,试试:
SqlQuery("select * from product where name like '@p0'", "%app%")
此外:
SqlQuery("select * from product where name like @p0", "'%app%'")
我打赌其中一个会起作用。