开发者

nhibernate audit trigger error

I'm using triggers o开发者_Python百科n my sql database to capture change information for a table, it seems to be having a problem with nhibernate though.

The table has a few columns and primary keys and triggers on it. The triggers look like this

CREATE TRIGGER [dbo].[tr_Instrument_update] ON [dbo].[Instrument] FOR UPDATE AS
BEGIN
  INSERT [MyAudit].[audit].[Instrument]
  SELECT 'Updated', i.*
    FROM inserted
   INNER JOIN [MyAudit].[dbo].[Instrument] i ON inserted.[InstrumentID] = i.[InstrumentID]
END

Basically on every change we copy the row into the audit table. I have tested and if I modify the data directly through sql management studio triggers function correctly and I get data written to the audit table, however if i update through my app I get the following:

NHibernate.StaleObjectStateException was unhandled by user code

Message=Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)

I assume this is because the trigger updates another table in another database, is there anyway to make nhibernate ignore this as the change will not affect any of its data, in our mappings we have no reference to this audit data.


Figured out that the trigger was causing Nhibernate to do two identical update calls for some reason. The solution was to SET NOCOUNT ON inside the trigger. Still not sure though why nhibernate makes two updates!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜