2013-05-02 76 views
0

ActiveRecord的MAPE:Castle Activerecord错误是Postgresql上的“关系不存在”?

[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

DB连接:

enter image description here

DB配置:

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上的应用程序启动:

enter image description here

测试例如表:

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

     return jobTitle.Title; 
    } 

错误获取上的活动记录:

enter image description here

Trace是:

enter image description here

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

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

我怎样才能解决这个问题,铸造?

+0

你已经孤立了原因。如果您无法修复查询生成器,则只需使用所有小写表名称即可解决该问题。 – 2013-05-02 04:48:58

+0

**克雷格林格** - 有什么区别小或大字符?,和我的问题Castle ActiveRecord查询到Pgsql sql铸造,为exp:'public.jobtitle-> public。“jobtitle”'。 – Elyor 2013-05-02 04:54:04

回答

4

PostgreSQL标识符是区分大小写; "JobTitle""jobtitle"不一样。但是,未加引号的标识符是大小写合并为的小写字母。 SQL标准要求大小写折叠。

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

CREATE TABLE "JobTitle" (...) 

你必须始终把它称为:

SELECT * FROM "JobTitle"; 

如果省略报价:

SELECT * FROM JobTitle; 

的PostgreSQL案例折叠JobTitlejobtitle,你会得到一个关于表01的错误不存在。

一致地引用或使用所有小写字母标识符。

更多在lexical structure section of the user manual

+0

ok right!,thx for answ :)。我现在的问题不是现在的任何,而是使用Castle ActiveRecord合并的pg sql语法! – Elyor 2013-05-02 05:07:45

+0

我有这个类的逻辑。这里:'[ActiveRecord("JobTitle",Schema="public“)]' – Elyor 2013-05-02 05:12:18

+0

@lelyor我真的不知道你想说什么与这些评论。 – 2013-05-02 05:27:23

0

我得到了同样的问题,但ActiveRecordStarter.CreateSchema();解决了我的问题。我猜你必须在ActiveRecordStarter初始化后放置这一行代码。

+0

好的,我可以优化这个问题吗? – Elyor 2014-01-09 08:04:38

相关问题