开发者

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 wou开发者_如何学Gold 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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜