<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: NHibernate and TooManyRowsAffectedException</title>
	<atom:link href="http://www.codewrecks.com/blog/index.php/2009/03/25/nhibernate-and-toomanyrowsaffectedexception/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codewrecks.com/blog/index.php/2009/03/25/nhibernate-and-toomanyrowsaffectedexception/</link>
	<description>Wrecks of code floating in the sea of Internet</description>
	<lastBuildDate>Mon, 06 Sep 2010 12:34:55 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: IT编程之家 &#187; Blog Archive &#187; NHibernate and TooManyRowsAffectedException(转载)</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/03/25/nhibernate-and-toomanyrowsaffectedexception/comment-page-1/#comment-3102</link>
		<dc:creator>IT编程之家 &#187; Blog Archive &#187; NHibernate and TooManyRowsAffectedException(转载)</dc:creator>
		<pubDate>Tue, 18 May 2010 05:26:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/03/25/nhibernate-and-toomanyrowsaffectedexception/#comment-3102</guid>
		<description>[...] NHibernate and TooManyRowsAffectedException(转载) IT Admin 发表于 2010-05-18 13:23 &#124; 来源： &#124; 阅读 0 views   阅读: 20 评论: 0 作者: 阿建 发表于 2010-05-18 11:55 原文链接Today I received a log of an error in a windows service that runs some scheduled actions, the error was TooManyRowsAffectedException and it is thrown by nhibernate when a session is flushed. The exact message said Unexpected row count: 2; expected: 1 , after a little moment of confusion I immediately realize that the problem is due to a trigger.I modified a table to keep a log of all modifications of every row, and I did this with a simple trigger that, for each update, saves the last value of each modified row in an history table. Since the trigger runs in the same context of the update operation, when you update a row, the trigger fired, insert a row in history table and the whole update operation returns 2 as the number of affected rows. NHibernate check the affected row count to verify that the row was really updated by the UPDATE statement, when he saw a rowcount of 2 he throws exception because something was wrong since it issue an update of a single row.The obvious solution is to issue a SET NOCOUNT ON at the beginning of the trigger and a SET NOCOUNT OFF at the end. This is a good practice, because in this way the trigger does not affect the number of affected rows. After all the trigger should be completely transparent to the application, and this is the best way to achieve this result.From:http://www.codewrecks.com/blog/index.php/2009/03/25/nhibernate-and-toomanyrowsaffectedexception/ [...]</description>
		<content:encoded><![CDATA[<p>[...] NHibernate and TooManyRowsAffectedException(转载) IT Admin 发表于 2010-05-18 13:23 | 来源： | 阅读 0 views   阅读: 20 评论: 0 作者: 阿建 发表于 2010-05-18 11:55 原文链接Today I received a log of an error in a windows service that runs some scheduled actions, the error was TooManyRowsAffectedException and it is thrown by nhibernate when a session is flushed. The exact message said Unexpected row count: 2; expected: 1 , after a little moment of confusion I immediately realize that the problem is due to a trigger.I modified a table to keep a log of all modifications of every row, and I did this with a simple trigger that, for each update, saves the last value of each modified row in an history table. Since the trigger runs in the same context of the update operation, when you update a row, the trigger fired, insert a row in history table and the whole update operation returns 2 as the number of affected rows. NHibernate check the affected row count to verify that the row was really updated by the UPDATE statement, when he saw a rowcount of 2 he throws exception because something was wrong since it issue an update of a single row.The obvious solution is to issue a SET NOCOUNT ON at the beginning of the trigger and a SET NOCOUNT OFF at the end. This is a good practice, because in this way the trigger does not affect the number of affected rows. After all the trigger should be completely transparent to the application, and this is the best way to achieve this result.From:http://www.codewrecks.com/blog/index.php/2009/03/25/nhibernate-and-toomanyrowsaffectedexception/ [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ajian</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/03/25/nhibernate-and-toomanyrowsaffectedexception/comment-page-1/#comment-3101</link>
		<dc:creator>Ajian</dc:creator>
		<pubDate>Tue, 18 May 2010 03:28:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/03/25/nhibernate-and-toomanyrowsaffectedexception/#comment-3101</guid>
		<description>I have solved the exception;Thank you.</description>
		<content:encoded><![CDATA[<p>I have solved the exception;Thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gabriel</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/03/25/nhibernate-and-toomanyrowsaffectedexception/comment-page-1/#comment-3051</link>
		<dc:creator>Gabriel</dc:creator>
		<pubDate>Tue, 20 Apr 2010 17:45:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/03/25/nhibernate-and-toomanyrowsaffectedexception/#comment-3051</guid>
		<description>this article was very helpfull for, thanks</description>
		<content:encoded><![CDATA[<p>this article was very helpfull for, thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marcus Mobley</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/03/25/nhibernate-and-toomanyrowsaffectedexception/comment-page-1/#comment-2202</link>
		<dc:creator>Marcus Mobley</dc:creator>
		<pubDate>Tue, 14 Apr 2009 21:34:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/03/25/nhibernate-and-toomanyrowsaffectedexception/#comment-2202</guid>
		<description>OMG Thank you!  I spent half a day looking for this answer!  Being a newbie to NHibernate I assumed it was a problem with my mapping...</description>
		<content:encoded><![CDATA[<p>OMG Thank you!  I spent half a day looking for this answer!  Being a newbie to NHibernate I assumed it was a problem with my mapping&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reflective Perspective - Chris Alcock &#187; The Morning Brew #315</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/03/25/nhibernate-and-toomanyrowsaffectedexception/comment-page-1/#comment-2146</link>
		<dc:creator>Reflective Perspective - Chris Alcock &#187; The Morning Brew #315</dc:creator>
		<pubDate>Thu, 26 Mar 2009 08:36:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/03/25/nhibernate-and-toomanyrowsaffectedexception/#comment-2146</guid>
		<description>[...] NHibernate and TooManyRowsAffectedException - Alkampfer shares a useful reminder about triggers in the database causing problems with Data Access code, in this case NHibernate, due to them returning extra &#8216;rows affected&#8217; counts. The solution and and a contender for your best practice guide is of course useing NO COUNT in triggers [...]</description>
		<content:encoded><![CDATA[<p>[...] NHibernate and TooManyRowsAffectedException &#8211; Alkampfer shares a useful reminder about triggers in the database causing problems with Data Access code, in this case NHibernate, due to them returning extra &#8216;rows affected&#8217; counts. The solution and and a contender for your best practice guide is of course useing NO COUNT in triggers [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arjan`s World &#187; LINKBLOG for March 25, 2009</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/03/25/nhibernate-and-toomanyrowsaffectedexception/comment-page-1/#comment-2144</link>
		<dc:creator>Arjan`s World &#187; LINKBLOG for March 25, 2009</dc:creator>
		<pubDate>Wed, 25 Mar 2009 14:56:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/03/25/nhibernate-and-toomanyrowsaffectedexception/#comment-2144</guid>
		<description>[...] NHibernate and TooManyRowsAffectedException - Alkampfer [...]</description>
		<content:encoded><![CDATA[<p>[...] NHibernate and TooManyRowsAffectedException &#8211; Alkampfer [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
