In PetaPoco, how to decorate a table that has multi-columns primary keys
Asked Answered
V

1

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.

Von answered 31/8, 2011 at 14:33 Comment(0)
B
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

Boxing answered 1/9, 2011 at 2:45 Comment(3)
Just curious if this composite key capability has been merged back into the TopTen branch? BTW what is NPoco? The next PetaPoco?Chartism
@Chartism 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.Boxing
@Boxing 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: github.com/mdimoudis/PetaPocoHath

© 2022 - 2024 — McMap. All rights reserved.