8

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.

Kevin Le - Khnle
  • 10,579
  • 11
  • 54
  • 80

1 Answers1

17

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

Schotime
  • 15,707
  • 10
  • 46
  • 75
  • Just curious if this composite key capability has been merged back into the TopTen branch? BTW what is NPoco? The next PetaPoco? – Guy--L Jun 06 '12 at 18:56
  • @Guy--L NPoco is my branch made into its own project. Unlikely composite key stuff would make it back into official PetaPoco which is why I have moved all my stuff to a new proj. – Schotime Jun 07 '12 at 05:01
  • 1
    @Schotime thanks for your branch! I ran into a HUGE issue where I had tables with 3 string primary keys with 4000+ records and PetaPoco was not able to properly insert/update using the auto-generated T4 template. I managed to modify the T4 template and add support for multiple string primary keys without doing extra work! Updating 4000+ records took around 3 minutes with totally inaccurate results, now this takes 5 seconds and the data is accurate! My branch can be found here: https://github.com/mdimoudis/PetaPoco – dimoss Jun 28 '12 at 03:19