【问题标题】:Replace the string concatenation in Migration script替换迁移脚本中的字符串连接
【发布时间】:2020-04-21 16:01:40
【问题描述】:

我正在使用下面的迁移脚本来查询带有 EF 核心的 postgreSQL,对于列名和表名,我需要用这个符号 " " 括起来。

根据上述条件,我正在编写如下脚本,有什么方法可以逃避与+ 符号的串联

migrationBuilder.Sql("UPDATE " + "\"" + "LibraryPipePlantTypes" + "\"" + " SET " + "\"" + "MasterSectionName" + "\"" + " = "+ "'" + "Library Pipe Plant Type" + "'" + " WHERE" + "\"" + "MasterSectionName" + "\"" + " = " + "'" + "Library Hydronic Plant Type" + "'");

非常感谢。

【问题讨论】:

  • 你试图用转义字符写出字符串,但没有连接?喜欢"UPDATE \"LibraryPipePlantTypes\" SET"?其他关于 SO 的讨论和示例发现 here

标签: c# .net string c#-8.0


【解决方案1】:

你可以试试

migrationBuilder.Sql('UPDATE "LibraryPipePlantTypes" SET "MasterSectionName" = "Library Pipe Plant Type" WHERE "MasterSectionName" = "Library Hydronic Plant Type"');

【讨论】:

  • 遗憾的是,C# 不允许字符串文字使用单引号。
猜你喜欢
  • 2014-11-24
  • 2018-05-08
  • 2010-09-27
  • 1970-01-01
  • 2020-07-23
  • 1970-01-01
  • 1970-01-01
  • 2015-05-19
  • 2021-10-05
相关资源
最近更新 更多