NHibernate - Updating a table with a trigger on it causes an error - Unexpected row count: 2; expected: 1

痴心易碎 提交于 2019-12-22 01:25:25

问题


So I'm trying to update an object in my MS SQL 2005 database using NHibernate. Please keep in mind that this is a legacy database used in many live systems and I can't remove the triggers.

When my data provider tries to .SaveOrUpdate() a row I get two returns (one for the actual update, and one when the trigger executes)

The raw return looks like this:

(1 row(s) affected)

(1 row(s) affected)

NHibernate then throws an exception like this: "Unexpected row count: 2; expected: 1"

I'm essentially looking an equivalent to "SET NOCOUNT ON" from within the session.

Any ideas?


回答1:


And you can't update the trigger to disable/enable the SET NOCOUNT before/after the trigger's code ?

SET NOCOUNT ON -- your trigger SET NOCOUNT OFF




回答2:


NHibernate JIRA NH-1353 provides a patch to deactive row count checking in the config file. It appears that this patch hasn't made it into the 2.x trunk.



来源:https://stackoverflow.com/questions/821981/nhibernate-updating-a-table-with-a-trigger-on-it-causes-an-error-unexpected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!