gpt4 book ai didi

c# - Postgresql 上的 CaSTLe Activerecord 错误是 “relation does not exist”?

转载 作者:行者123 更新时间:2023-11-29 14:11:57 29 4
gpt4 key购买 nike

ActiveRecord 映射:

[ActiveRecord("JobTitle",Schema="public")] 
public class JobTitle :ActiveRecordValidationBase<JobTitle>
{

[PrimaryKey(Column = "Id")]
public virtual int Id { get; set; }

[Property(Column = "Description")]
public virtual string Description { get; set; }

[Property(Column = "Title", NotNull = true)]
public virtual string Title { get; set; }

}

enter image description here

数据库连接:

enter image description here

数据库配置:

 public class DbConfig
{

public static void Configure()
{

var connectionString=ConfigurationManager.ConnectionStrings["PgConnection"].ConnectionString;
var source = ActiveRecordSectionHandler.Build(DatabaseType.PostgreSQL82,connectionString);

ActiveRecordStarter.Initialize(source, typeof(JobTitle));


}


}

然后 init on app 开始了:

enter image description here

测试表的例子:

    //
// GET: /Home/
public string Index()
{
var jobTitle= JobTitle.TryFind(1);

return jobTitle.Title;
}

获取事件记录时出错:

enter image description here

跟踪是:

enter image description here

我知道请求是错误的。因为错误地发送到 pg sql 查询。这个对我的“JobTitle”表的简单查询:

  select * from public.jobtitle => Castle Active Record
select * from public."jobtitle" => Pg

如何解决这个转换问题?

最佳答案

PostgreSQL 标识符区分大小写“JobTitle”“jobtitle” 不同。但是,未加引号的标识符将大小写折叠 为小写。 SQL 标准要求大小写折叠。

这意味着如果您创建一个表:

CREATE TABLE "JobTitle" (...)

您必须始终将其称为:

SELECT * FROM "JobTitle";

如果省略引号:

SELECT * FROM JobTitle;

PostgreSQL 将 JobTitle 大小写折叠为 jobtitle,您将收到有关表 jobtitle 不存在的错误。

要么一致引用,要么使用所有小写标识符。

更多内容在 lexical structure section of the user manual .

关于c# - Postgresql 上的 CaSTLe Activerecord 错误是 “relation does not exist”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16330468/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com