0

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

}

enter image description here

DB connection:

enter image description here

DB config:

 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:

enter image description here

Test for example the Table:

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

        return jobTitle.Title;
    }

Error getting on Active record:

enter image description here

Trace is :

enter image description here

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 

How can I solve this casting problem?

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
Elyor
  • 900
  • 1
  • 12
  • 26
  • You've already isolated the cause.If you can't fix the query generator, just use all lower case table names to work around it. – Craig Ringer May 02 '13 at 04:48
  • **Craig Ringer** - what's the difference small or large characters?,and my problem Castle ActiveRecord query to Pgsql sql casting , for exp:`public.jobtitle->public."jobtitle"`. – Elyor May 02 '13 at 04:54

2 Answers2

4

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" (...)

you must consistently refer to it as:

SELECT * FROM "JobTitle";

if you omit the quotes:

SELECT * FROM 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.

More in the lexical structure section of the user manual.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • ok right!,thx for answ :).My problem not now any, and pg sql syntax's using Castle ActiveRecord merging! – Elyor May 02 '13 at 05:07
  • I have the logic to this class.Here:`[ActiveRecord("JobTitle",Schema="public")]` – Elyor May 02 '13 at 05:12
  • @lelyor I'm really not sure what you're trying to say with those comments. – Craig Ringer May 02 '13 at 05:27
  • 1
    Very neatly explained. The simplest solution (IMHO) is not to use CamelCase identifiers for tables and columns in postgres, but to stick to underscore_separated_words instead. – IMSoP May 02 '13 at 08:30
0

I have got the same issue, but ActiveRecordStarter.CreateSchema(); solves my problem. I guess you have to put this line of code after initialization of ActiveRecordStarter.