2
votes

I'm working with a legacy table which I cannot change. The database have a settings table which consists of a lot of columns (one for each setting) and only one row:

Columns: Setting1  | Setting2     | Setting3  | etc...
         ----------+--------------+-----------+-------------
Row1:    SomeValue | AnotherValue | LastValue | etc...

Now, this would be all fine if it wasn't for the fact that the table lacks a primary key. Obviously, the original developer didn't think it was necessary, as there's only one single row.

Is there any way of mapping this with Nhibernate? I've already implemented a SQL based solution, but I'd love to have the flexibility and simplicity gained with Nhibernate.

I'm fearing the worst but, any ideas?

2
Why can't you change the table? Is it part of the Constitution or something? Just add a dummy Id column of any type, with any value. - Diego Mijelshon
The code is part of an integration with an ERP system, which in turn has a couple of other integrations working toward it from other angles. I don't want to fiddle with the table structures in case that would incur problems with other integrations or the ERP's update process. The integration will be sold to customers outside our company so I can't really tell exactly how the environment would look in production. - Kristoffer Lindvall

2 Answers

2
votes

Well, just pick any setting (column) as the Id. The only inconvenience is that if you need to change the setting that is the PK you'll have to delete and re-insert the row...

2
votes

You could map a view that adds a dummy PK column:

select 1 as SettingsId, Setting1, etc....

or load the object from a stored procedure.