This project is read-only.

Tables without primary keys

Nov 10, 2009 at 4:50 PM

Are there any plans to support tables without primary keys?  I have imported an existing schema which, unfortunately, has a number of tables without primary keys.  I understand that this is far from ideal, but I don't really have control over the schema.

Nov 10, 2009 at 7:12 PM

There are no plans to support this. Our suggestion is to add a surrogate key like RowId, Int, Identity. This will add a integer that auto increments. I have used this for some tables that did not have PK. This is of course a schema change. If you cannot change the schema then you cannot use the nHydrate tool.

Nov 10, 2009 at 10:00 PM

Thanks for the quick reply.  We don't generate most of the tables without PKs anyhow.  The few that we do use have actually have a key (conceptually), it just isn't enforced as a database constraint (irritating... but I didn't design it) so I should be able to get by.  I'll have to take a closer look and see if it will be a real problem for us.

Nov 10, 2009 at 10:22 PM

If the field is essentially a PK then just mark it as such. This will generate the script to make it a PK but you can delete this manually before running the database scripts. It does not really have to be a PK in database. The model will treat it as such.

Nov 11, 2009 at 4:10 AM

The latest version now has a EnforcePrimaryKey property. You must set a PK in the model but you do NOT have to enforce it in the database. This might be what you are looking for.