In the example given on PetaPoco's web site, this is how to decorate a class:
[PetaPoco.TableName("articles")]
[PetaPoco.PrimaryKey("article_id")]
public class article
{
public long article_id { get; set; }
public string title { get; set; }
public DateTime date_created { get; set; }
public bool draft { get; set; }
public string content { get; set; }
}
But assume that the table articles was modeled to have 2 columns: article_id and title as its primary key (instead of just article_id), then how the decoration in PetaPoco would look like.
Each table can only have one primary key. Access can automatically create a primary key field for you when you create a table, or you can specify the fields that you want to use as the primary key.
A table can have only one primary key, which may consist of single or multiple fields. When multiple fields are used as a primary key, they are called a composite key. If a table has a primary key defined on any field(s), then you cannot have two records having the same value of that field(s).
For a constraint to be recognized as a primary key, it must contain unique values throughout the row and none of the values must be NULL. In a table, there can only be one primary key. A primary key can have one or as many columns as possible.
No. You cannot use more than 1 primary key in the table. for that you have composite key which is combination of multiple fields.
This currently only works in my branch, but you can do this.
[PetaPoco.PrimaryKey("article_id,title")]
My branch can be found here. https://github.com/schotime/PetaPoco
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With