【问题标题】:entity framework LIKE query实体框架 LIKE 查询
【发布时间】:2013-03-17 02:19:02
【问题描述】:

我将 EF4.1 与 MySql 一起使用,但无法让 LIKE 查询正常工作。我想获取名称为 app 的产品列表

.Where(p=>p.Name.Contains("app") 仅返回一个名为 Apple 的产品。生成的 SQL 包含 LOCATE 运算符代替 LIKE '%app%'

我尝试使用 SqlQuery("select * from product where name like '%@p0%'", "app") 执行 sql 命令,但无济于事。它不会重新运行任何产品。

请建议我如何为 MySql db 编写 LIKE。谢谢

【问题讨论】:

  • 我们遇到了同样的问题
  • 我也有同样的问题。有什么解决办法吗?

标签: mysql entity-framework-4.1


【解决方案1】:

我不知道 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%'")

我敢打赌其中一个会起作用。

【讨论】:

    猜你喜欢
    • 2012-07-31
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    • 2014-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多