我的模型看起來像這樣...如何爲PetaPoco和PostgreSQL創建表/列名的大小寫?
[PrimaryKey("TaskId")]
public class Task
{
public int TaskId { get; set; }
[StringLength(1000)]
[DisplayName("What do you want to do?")]
public string Description { get; set; }
[DisplayName("When do you want it done?")]
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = false)]
[DataType(DataType.Date)]
public DateTime CompleteByDate { get; set; }
public bool IsCompleted { get; set; }
public DateTime InsertDate { get; set; }
public DateTime UpdateDate { get; set; }
}
如果我試圖從任務表中提取數據,我首先看到的錯誤之一是這樣的......
ERROR: 42P01: relation "Task" does not exist
的問題,據我可以告訴的是,PetaPoco產生這樣的SQL ...
SELECT "Task"."TaskId", "Task"."Description", "Task"."CompleteByDate", "Task"."IsCompleted", "Task"."InsertDate", "Task"."UpdateDate" FROM "Task"
所以,用引號,資本事項,並在數據庫中列名只能在認可如果將它們放在引號中,則爲小寫。我想知道是否有辦法改變這種情況。我目前看到的唯一的解決辦法是讓我的模型看起來就像這樣(注意大小寫變化)...
[PrimaryKey("taskid")]
[TableName("task")]
public class Task
{
[Column("taskid")]
public int taskid { get; set; }
[StringLength(1000)]
[DisplayName("What do you want to do?")]
public string description { get; set; }
[DisplayName("When do you want it done?")]
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = false)]
[DataType(DataType.Date)]
public DateTime completebydate { get; set; }
public bool iscompleted { get; set; }
public DateTime insertdate { get; set; }
public DateTime updatedate { get; set; }
}
我不希望我的屬性全部小寫。爲什麼我必須這樣做,這是唯一的解決辦法嗎?
謝謝,那就是訣竅。 – Carter