NHibernate 1.0.2
MSDE 2000
Code:
I have a table similar to the following:
CREATE TABLE [MyTable] (
[MyTablleId] [int] NOT NULL PRIMARY KEY NONCLUSTERED ,
[MyParentTableId] [int] NOT NULL ,
[Col1] [varchar] (100) NOT NULL ,
[Col2] [varchar] (100) NULL ,
[Col3] [varchar] (100) NULL ,
[Col4] [varchar] (100) NULL ,
CONSTRAINT [FK_MyTable_MyParentTable] FOREIGN KEY
(
[MyParentTableId]
) REFERENCES [MyParentTable] (
[MyParentTableId]
)
)
// Index for performance
CREATE CLUSTERED INDEX [MyTable_SS1] ON [MyTable]
(MyParentTableId)
GO
// Business logic index
CREATE UNIQUE NONCLUSTERED INDEX [MyTable_SS2] ON [MyTable]
(MyParentTableId, Col1, Col2, Col3)
GO
So I have a foreign key to MyParentTable, an index on this column for performance and then a business logic index to ensure no duplicates exist with the same values for Col1, 2 and 3.
In my application I have a situation where the user enters what is initially a duplicate entry and then changes the existing entry so no duplicates occur.
I use session.SaveOrUpdate and NHibernate performs the insert first which causes a violation of the second index. It needs to perform the update first then the insert.
Is there something wrong in the way I am defining my table which is causing this or can I specify the order of inserts/updates?