使用.ALL和LINQ查询数据库时发生异常

时间:2019-03-11 09:42:32

标签: mysql entity-framework linq entity-framework-6 mysql-connector

试图获得结果,searchTerms中的所有关键字都出现在标题栏中。

我的代码

 var listRes = db.tbl1
      .Where(g => searchTerms.All(x => g.title.Contains(x)))
      .ToList();

searchTerms是一个带有单个字符串条目“ stars”的数组。该表包含所有填充的单行,包括title字段。

错误:

System.Data.Entity.Core.EntityCommandExecutionException
  HResult=0x8013193C
  Message=An error occurred while executing the command definition. See the inner exception
  for details.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

Inner Exception 1:
 MySqlException: You have an error in your SQL syntax; check the manual that corresponds to
 your MySQL server version for the right syntax to use near '%stars%) OR 
 (CASE WHEN (`Extent1`.`title` LIKE %stars%) THEN (1) 
 WHEN (`Extent1' at line 25

使用:

MySQL 5.7.24

MySQL连接器6.9.8.0

实体框架6.0

Visual Studio 2017社区

0 个答案:

没有答案