c# - dapper.contrib postres 42P01 错误:关系“”不存在使用 dapper.contrib,我不断收到错误:'42P01: relation "tblproduct" does not exist'
.
我相信这是因为 postgresql 区分大小写。实体本身具有 的模式注释'[Table("tblProduct")]'
。
我找不到为什么生成的 sql 会使用小写的
问题描述
使用 dapper.contrib,我不断收到错误:'42P01: relation "tblproduct" does not exist'
.
我相信这是因为 postgresql 区分大小写。实体本身具有 的模式注释'[Table("tblProduct")]'
。
我找不到为什么生成的 sql 会使用小写的表名?我正在使用'SqlMapperExtensions.TableNameMapper'
来强制案例,但这也不起作用。我错过了什么吗?谢谢
public ICollection<Product> GetAll(int count)
{
if (SqlMapperExtensions.TableNameMapper != null)
return null;
SqlMapperExtensions.TableNameMapper = (type) =>
{
return "tblProduct";
};
using (var connection = new NpgsqlConnection(connectionString))
{
connection.Open();
return connection.GetAll<Product>().Take(count).ToList();
}
}
您可以尝试以下几行:
PGPASSWORD=password;
pg_restore --host "hostname" --port "port" --username "postgres" --no-password --verbose --dbname "dbname" --schema "schema" "dump_filename";
其中“hostname”是 postgresql 服务器的主机名(localhost),“port”是监听 postgresql 服务器的端口(5432),“postgres”是用户名,“dbname”是数据库名称
解决方案
您可以看到 Dapper 生成的内容:
NpgsqlLogManager.Provider = new ConsoleLoggingProvider(NpgsqlLogLevel.Trace, true, true);
我用 qutoes 解决了我在 PostgresSQL 上的问题:
SqlMapperExtensions.TableNameMapper = (type) => $"\"{type.Name}s\"";
推荐阅读
- python - TF 数据集是否有等效的 tf.gather() ?
- javascript - 仅使用 php、html 和 vanila js 将 TimeZone 放在两个选择标签中
- python - 如何从 MQ 系统中的服务器获取响应(python)
- html - 使用标签构建进度条
- cypress - 如何在 Cypress 中获取隐藏元素的 HTML?
- java - 底部导航菜单 onClick 图标选择
- c# - 使用 wpf 按子类别过滤订单表
- android - 错误:Android Gradle 插件仅支持 Butterknife Gradle 插件版本 9.0.0-rc2 及更高版本
- php - 无法将数据库中的字段加载到组合框
- javascript - 有没有办法创建一条从时间轴上的标记到文本的线?
使用 dapper.contrib,我不断收到错误:'42P01: relation "tblproduct" does not exist'
.
我相信这是因为 postgresql 区分大小写。实体本身具有 的模式注释'[Table("tblProduct")]'
。
我找不到为什么生成的 sql 会使用小写的
问题描述
使用 dapper.contrib,我不断收到错误:'42P01: relation "tblproduct" does not exist'
.
我相信这是因为 postgresql 区分大小写。实体本身具有 的模式注释'[Table("tblProduct")]'
。
我找不到为什么生成的 sql 会使用小写的表名?我正在使用'SqlMapperExtensions.TableNameMapper'
来强制案例,但这也不起作用。我错过了什么吗?谢谢
public ICollection<Product> GetAll(int count)
{
if (SqlMapperExtensions.TableNameMapper != null)
return null;
SqlMapperExtensions.TableNameMapper = (type) =>
{
return "tblProduct";
};
using (var connection = new NpgsqlConnection(connectionString))
{
connection.Open();
return connection.GetAll<Product>().Take(count).ToList();
}
}
您可以尝试以下几行:
PGPASSWORD=password;
pg_restore --host "hostname" --port "port" --username "postgres" --no-password --verbose --dbname "dbname" --schema "schema" "dump_filename";
其中“hostname”是 postgresql 服务器的主机名(localhost),“port”是监听 postgresql 服务器的端口(5432),“postgres”是用户名,“dbname”是数据库名称
您可以看到 Dapper 生成的内容:
NpgsqlLogManager.Provider = new ConsoleLoggingProvider(NpgsqlLogLevel.Trace, true, true);
我用 qutoes 解决了我在 PostgresSQL 上的问题:
SqlMapperExtensions.TableNameMapper = (type) => $"\"{type.Name}s\"";