【问题标题】:How to escape { character in FromSqlRaw query如何在 FromSqlRaw 查询中转义 { 字符
【发布时间】:2021-09-26 13:19:10
【问题描述】:

在使用 Npsql EF Core 数据提供程序的 EF Core 中,查询类似

await ctx.Doc.FromSqlRaw(@"select * from Doc where id=any('{1,2,3}')");

报错

索引(从零开始)必须大于或等于零且小于参数列表的大小。

如何在查询中使用{} 字符,使它们不被视为参数?

【问题讨论】:

    标签: asp.net-core .net-core entity-framework-core npgsql


    【解决方案1】:

    与 string.Format 一样,使用双花括号来转义:

    await ctx.Doc.FromSqlRaw(@"select * from Doc where id=any('{{1,2,3}}')");
    

    【讨论】:

      猜你喜欢
      • 2020-01-08
      • 2012-03-26
      • 1970-01-01
      • 2016-03-10
      • 2017-09-06
      • 1970-01-01
      • 2018-02-06
      • 2013-05-02
      • 2011-05-09
      相关资源
      最近更新 更多