本文介绍了Castle Activerecord错误是Postgresql上的“关系不存在"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ActiveRecord映射:

ActiveRecord mape:

[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; }

}

数据库连接:

数据库配置:

 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)); 


    }


}

并在应用程序上启动了初始化:

And init on app started:

例如测试表格:

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

        return jobTitle.Title;
    }

在活动记录上出错:

踪迹是:

我了解该请求是rrrr.因为错误地发送至pg sql查询.这是我的"JobTitle"表的简单查询:

I understand that the request is еrror.Because incorrectly sending to pg sql query.And this simple query for my "JobTitle" table:

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

如何解决投放问题?

推荐答案

PostgreSQL标识符区分大小写; "JobTitle""jobtitle"不同.但是,未加引号的标识符会被大小写折叠转换为小写. SQL标准要求大小写折叠.

PostgreSQL identifiers are case sensitive; "JobTitle" isn't the same as "jobtitle". However, unquoted identifiers are case-folded to lower case. Case folding is required by the SQL standard.

这意味着如果您使用以下方法创建表:

This means that if you create a table with:

CREATE TABLE "JobTitle" (...)

您必须始终将其称为:

SELECT * FROM "JobTitle";

如果省略引号:

SELECT * FROM JobTitle;

PostgreSQL将JobTitle折叠到jobtitle,您将得到有关表jobtitle不存在的错误.

PostgreSQL case-folds JobTitle to jobtitle and you'll get an error about the table jobtitle no existing.

要么一致引用,要么使用所有小写字母标识符.

Either quote consistently or use all lower case identifiers.

用户手册的词汇结构部分中的更多内容.

这篇关于Castle Activerecord错误是Postgresql上的“关系不存在"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 01:21