Is it possible with NHibernate and Sql Server to insert an entity and set one of the column values to the newly generated identity?
In pure sql I can do it by adding the default value
Create the table:
create table Test
id int identity,
name varchar(12),
parentId int NOT NULL
Add a constraint:
alter table Test constraint ... default ident_current('Test') for parentId
And afterwards skip the parentId or use the DEFAULT keyword:
insert into Test values('TEST')
insert into Test values('TEST', DEFAULT)
Correct me if I'm wrong but I think that the above statements are never going to be generated by NHibernate?
For now I'm first saving my entity and then updating it with the newly created identity. This case brakes the db structure as I had to make that particular column accept NULLs.
At first I though this is going to be easy, but now, after several hours I still can't find the answer :/
Thanks in advance