What is the recommended way to create table with PetaPoco (and NPoco)?

2.3k Views Asked by At

Say I need a table that looks like this:

CREATE TABLE Record (
  Id INT IDENTITY(1, 1) PRIMARY KEY CLUSTERED,
  Guid UNIQUEIDENTIFIER UNIQUE NONCLUSTERED,
  Version ROWVERSION,
  DateOfBirth DATETIME2,
  Name VARCHAR(64) NOT NULL
)

What's the recommended way of creating the table above using PetaPoco and NPoco?

2

There are 2 best solutions below

3
On

PetaPoco is all about using SQL for what SQL does best. Therefore, the correct way to create a table with PetaPoco is to create it with SQL. We've had a few requests to add schema generation from POCOs, but every supported DB has their own take on DDL, and thus to add it (properly) would be a big undertaking.

It may be added some day, but right now development time is better spent on other features.

That said, PetaPoco is open source, so a PR, if done properly, for schema generation would be happily accepted ;)

Finally, although I don't follow NPoco all the closely, I don't think it has support for schema generation from POCOs, and at a guess, it would be due to the same reason listed above.

0
On

I use a migration tool (DbUp) to keep up with the changes in the schema.