简体   繁体   中英

Mapping a single row table without primary key using Nhibernate

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?

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...

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM