Hi guys and thanks for this magnificent product.
I have a design problem trying to use NHibernate on an existing database, which I don't figure out.
I have a SQLServer2005 database, with GUID as PK's. The problem is that for generating those keys, a default value of newsequencialid() is used.
My problem is that I cannot figure out a good way to map the existing tables with nhibernate, so I'd keep the database generated GUID.
Code:
[.........]
<id name="UserID" column="UserID" type="Guid">
<generator class="native"/>
</id>
[.........]
If I use the class=native value for generator, NHibernate trys to get the SCOPE_IDENTITY(), which works for INT, but not for GUID.
Another solution would be to use class="assigned", and to generate a new sequencialID using WinAPI [using UuidCreateSequential], but if the DB is on a different machine, this won't work as expected.
I searched for that, and it seems SQL2005 has an OUTPUT keyword that might come in handy:
Code:
insert into Category (CategoryName)
output Inserted.idCategory
values ('Ima Person')
This returns the guid generated by newsequencialid().
Any ideeas on how [if possible] to implement the output in NHibernate?
Or other suggestions?
Thanks,
Raul