问题
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; }
}
DB connection:
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:
Test for example the Table:
//
// GET: /Home/
public string Index()
{
var jobTitle= JobTitle.TryFind(1);
return jobTitle.Title;
}
Error getting on Active record:
Trace is :
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?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/16330468/castle-activerecord-error-is-relation-does-not-exist-on-postgresql