当前位置:Gxlcms > 数据库问题 > Sqlite 参数化 模糊查询 解决方案

Sqlite 参数化 模糊查询 解决方案

时间:2021-07-01 10:21:17 帮助过:12人阅读

以上的语句执行后的结果是错误的,在Dapper中,类似SQL语句中的like应该如何处理呢?

方案一

term = "whateverterm";
var encodeForLike = term => term.Replace("[", "[[]").Replace("%", "[%]");

string term = "%" + encodeForLike(term) + "%";
var data = conn.Query(@"
   select top 25 
  Term as Label, 
  Type, 
  ID 
  from SearchTerms 
  WHERE Term like @term", 
  new { term });

方案二

string query = "SELECT * from country WHERE Name LIKE CONCAT(‘%‘,@name,‘%‘);"
var results = connection.query<country>(query, new {name});

方案三

db.Query<Remitente>("SELECT * 
                     FROM Remitentes 
                     WHERE Nombre LIKE @n", new { n = "%" + nombre + "%" })
                   .ToList();

Sqlite 参数化 模糊查询 解决方案

标签:nec   模糊   csharp   rms   result   描述   select   tps   head   

人气教程排行