asp.netsql-serverexistscomposite-primary-keypetapoco

Composite primary keys with PetaPoco for Exists and GetById methods


I found this nice branch of PetaPoco by schootime which handles composite primary keys.

Now what I didn't find is how he handled in his version of PetaPoco methods which require a primary key, with composite keys like for example db.Exists and db.GetById methods.

With a single primary key you just pass the value but how to threat those methods with multiple keys? Should I pass a dictionary of string/object instead with the primary column name and the value?

If you are using this branch, any hint would be appreciated.

Also is there a way of using the Page method to query results for all the results with PetaPoco? Meaning passing no pages/items per page.


Solution

  • These methods take an object, which can be an anonymous object. eg.

    db.SingleById<User>(new{ Name="John", Email="John@smith.com"});