3

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?

Igor Gatis
  • 4,648
  • 10
  • 43
  • 66

2 Answers2

0

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.

Plebsori
  • 1,075
  • 9
  • 23
  • 1
    So, PetaPoco is totally agnostic on how changes to schema are made? I get the point of "staying away from the schema change" and focusing on the object mapping.I was looking for at least an advice (e.g. one may use FluentMigrator). – Igor Gatis Feb 17 '16 at 11:43
  • Ok sure I see what you're asking. To be honest, in all projects I've worked on where migrations have been built-in I've used [dbup](https://dbup.github.io/) to handle this. This effectively means I've been crafting the changes myself. I've dabbled with a few other methods, but never found one which has been flexible enough for my needs. FluentMigrator piqued my interest, I'm off to have a read. – Plebsori Feb 18 '16 at 00:31
  • I rather like SqlFu's take on it. Creating the SQL to create a table is still a manual job - but the framework helps you (for example by supplying column names for a given POCO property). I don't see how this approach couples you to a product-specific DDL any more than product-specific SELECT statements which I presume can already be accomplished through ad-hoc queries in PetaPoco – Jack Ukleja Jul 05 '16 at 07:19
0

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

Eduardo Molteni
  • 38,786
  • 23
  • 141
  • 206