<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" gd:etag="W/&quot;D08ARX09cSp7ImA9WhRXEkQ.&quot;"><id>tag:blogger.com,1999:blog-31061699</id><updated>2011-12-19T13:57:24.369+02:00</updated><title>Stephan Zahariev's Blog</title><subtitle type="html">Keen on .NET Framework, Delphi, DataStage, SQL Server, Teradata.</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>30</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/StephanZaharievBlog" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="stephanzaharievblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;C0EHSX4yeSp7ImA9WxFRFEg.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-6102991491291686554</id><published>2010-04-28T13:47:00.001+03:00</published><updated>2010-04-28T13:47:18.091+03:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-04-28T13:47:18.091+03:00</app:edited><title>Migrating ASP.NET MVC 1.0 to MVC 2.0: Real World Scenario</title><content type="html">&lt;p&gt;As most of you have noticed, ASP.NET MVC v.2.0 has been &lt;a href="http://weblogs.asp.net/scottgu/archive/2010/03/11/asp-net-mvc-2-released.aspx"&gt;released&lt;/a&gt; last month. The new version introduces lots of cool features, so most of the existing MVC 1 applications will be upgraded to the new release. In the current post I will try to share my experience with migrating existing ASP.NET MVC 1.0 application to MVC 2.0.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Scenario&lt;/strong&gt;: There is an existing ASP.NET MVC 1.0 web application build on top of .NET Framework 3.5, jQuery and Visual Studio 2008. The goal is to migrate the application to MVC 2, while keeping the other libraries and tools (.NET 3.5, VS2008, etc).&lt;/p&gt; &lt;h3&gt;Identifying the breaking changes&lt;/h3&gt; &lt;p&gt;The first step from the process would be to check the ASP.NET MVC 2.0 &lt;a href="http://www.asp.net/learn/whitepapers/what-is-new-in-aspnet-mvc/#_TOC5"&gt;breaking changes&lt;/a&gt;. Naturally after carefully evaluating each item in the breaking changes list, I have find out that the following will be a problem: “&lt;em&gt;JsonResult now responds only to HTTP POST requests&lt;/em&gt;”. The problem was caused by a jQuery plug-in that uses only HTTP GET. So the solution was to:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Replace the plug-in by someone more configurable that can use HTTP POST. You should do it in case that your application exposes sensitive information and is vulnerable to the attack described &lt;a href="http://haacked.com/archive/2009/06/25/json-hijacking.aspx"&gt;here&lt;/a&gt;.  &lt;li&gt;Explicitly allow HTTP GET on JsonResults. You can do it by using the JsonRequestBehavior.AllowGet&lt;/li&gt;&lt;/ul&gt; &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[AcceptVerbs(HttpVerbs.Get)]&lt;br&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; JsonResult GetData()&lt;br&gt;{&lt;br&gt;    &lt;span style="color: #008000"&gt;//Some other code&lt;/span&gt;&lt;br&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; Json(data, JsonRequestBehavior.AllowGet);&lt;br&gt;}&lt;/pre&gt;&lt;br&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;I was lucky that the information exposed in my application was not sensitive, so I decided to use the &lt;em&gt;JsonRequestBehavior.AllowGet&lt;/em&gt;.&lt;/p&gt;&lt;br /&gt;&lt;h3&gt;Migrating the solution to build against ASP.NET MVC 2.0&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;Being confident that I have resolved all breaking changes I had to think about migrating the solution to use the new version of MVC 2.0. If you don’t want to do everything by hand, you should use &lt;a href="http://weblogs.asp.net/leftslipper/archive/2010/03/10/migrating-asp-net-mvc-1-0-applications-to-asp-net-mvc-2-rtm.aspx"&gt;this&lt;/a&gt; tool. The tool is build by one of the &lt;a href="http://www.microsoft.com"&gt;Microsoft&lt;/a&gt; employees and works &lt;strong&gt;GREAT&lt;/strong&gt;. However, I have noticed a few gotchas. The tool insists to backup your project before the conversion. This seems redundant, because usually the source code stays in code repository and if somehow the conversion produces a mess, everything could be restored. After all I had to wait a few extra minutes for the backup (more than 1GB in my case). The second issue that I have found is the update of the jQuery files. The tool updates the jQuery and Microsoft AJAX libraries. Since the web site was relying on several other 3rd party jQuery plug-ins I didn’t want the jQuery upgrade. So I had to manually remove the update. Despite of the above, the tool is absolutely &lt;strong&gt;FANTASTIC&lt;/strong&gt; an you will need it.&lt;/p&gt;&lt;br /&gt;&lt;h3&gt;Running the application&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;Up to now, everything went pretty well and the solution compiled without problems. So I was ready to run it. After hitting F5 I was stunned. The application started to close and open pages by itself! With the help of a few unit tests and Goolge I was able to identify the source of the problem. It turns out that there is another undocumented breaking change: a value from &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.controllerbase.tempdata.aspx"&gt;TempData&lt;/a&gt; dictionary will be removed after the request in which it is read! You can read more &lt;a href="http://blog.donnfelker.com/2010/02/26/aspnet-mvc2-tempdata-now-persists/"&gt;here&lt;/a&gt;. The fix was relatively easy and soon everything was working as usual.&lt;/p&gt;&lt;br /&gt;&lt;h3&gt;Bottom line&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;The migration process from ASP.NET MVC 1.0 to MVC 2.0 is relatively easy and you should do it. The new features are awesome.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-6102991491291686554?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/6102991491291686554/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=6102991491291686554" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/6102991491291686554?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/6102991491291686554?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2010/04/migrating-aspnet-mvc-10-to-mvc-20-real.html" title="Migrating ASP.NET MVC 1.0 to MVC 2.0: Real World Scenario" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total></entry><entry gd:etag="W/&quot;CEIAQ3g7eyp7ImA9WhdXGE0.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-3857228549661646922</id><published>2010-03-26T01:54:00.003+02:00</published><updated>2011-08-31T17:55:42.603+03:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-31T17:55:42.603+03:00</app:edited><title>ASP.NET MVC Best Practices – Routes to Ignore</title><content type="html">Routing is a key feature from the &lt;a href="http://www.asp.net/mvc"&gt;ASP.NET MVC&lt;/a&gt;. If you are not familiar with this concept, take a look &lt;a href="http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx"&gt;here&lt;/a&gt;, because I’m not going to explain it. I’m going to share some routes that you should ignore in your configuration.&lt;br /&gt;
So maybe you are wondering, why should I ignore some routes? And the simple answer is: Because most of the time, different search engines/crawlers/bots will try to index your site and they will request for specific files. For example, &lt;a href="http://www.google.com/"&gt;Google&lt;/a&gt; will try to access the following file: &lt;a href="http://yoursite.com/robots.txt"&gt;http://yoursite.com/robots.txt&lt;/a&gt;. The &lt;i&gt;robots.txt&lt;/i&gt; file is used to to give instructions about your site to web robots. More info can be found &lt;a href="http://en.wikipedia.org/wiki/Robots_exclusion_standard"&gt;here&lt;/a&gt;. Up to now, everything sounds great, but if your site does not have robots.txt file, the ASP.NET MVC framework will raise an exception upon a request like the above. So your log, where the unhandled exceptions are reported can be flooded with messages like:&lt;br /&gt;
System.Web.HttpException : A public action method 'robots.txt' could not be found&lt;br /&gt;
on controller 'YourPage.Controllers.YourController'.&lt;br /&gt;
Obviously, there are two ways to handle this – provide a dummy robots.txt file or instruct the ASP.NET MVC framework to ignore such URL’s. I prefer the second approach. In this post I will try to summarize all the URL’s that should be ignored by the ASP.NET application. So, here they are:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Robots_exclusion_standard"&gt;~/robots.txt&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;i&gt;&lt;a href="http://en.wikipedia.org/wiki/Site_map"&gt;~/sitemap&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;i&gt;~/sitemap.gz&lt;/i&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Sitemaps"&gt;~/sitemap.xml&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;i&gt;&lt;a href="http://www.microsystools.com/products/sitemap-generator/faq/xml-sitemaps-compression-gzip/"&gt;~/sitemap.xml.gz&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;i&gt;~/google_sitemap.xml&lt;/i&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;i&gt;~/google_sitemap.xml.gz&lt;/i&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Favicon"&gt;~/favicon.ico&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;~/mobile&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;~/iphone&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.webmasterworld.com/html/3560399.htm"&gt;~/apple-touch-icon.png&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;i&gt;~/sitemap.txt&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;i&gt;~/sitemap.rss&lt;/i&gt;&lt;/li&gt;
&lt;/ul&gt;You need to ignore the routes above, ONLY if your site do not uses such a file. If you are not familiar with the sitemaps concept,&amp;nbsp; &lt;a href="http://www.forestsoftware.co.uk/do-i-need-a-site-map.html"&gt;here&lt;/a&gt; is a quick overview that answers to most of the questions.&lt;br /&gt;
Here is the code, taken from the &lt;a href="http://msdn.microsoft.com/en-us/library/2027ewzw.aspx"&gt;Global.asax.cs&lt;/a&gt; file that should ignore some of the URL’s outlined above:&lt;br /&gt;
&lt;div id="codeSnippetWrapper" style="background-color: #f4f4f4; border: 1px solid silver; cursor: text; direction: ltr; font-family: 'Courier New',courier,monospace; font-size: 8pt; line-height: 12pt; margin: 20px 0px 10px; max-height: 200px; overflow: auto; padding: 4px; text-align: left; width: 97.5%;"&gt;&lt;pre id="codeSnippet" style="background-color: #f4f4f4; border-style: none; color: black; direction: ltr; font-family: 'Courier New',courier,monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; text-align: left; width: 100%;"&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute(&lt;span style="color: #006080;"&gt;"{resource}.axd/{*pathInfo}"&lt;/span&gt;);

routes.IgnoreRoute(&lt;span style="color: #006080;"&gt;"robots.txt"&lt;/span&gt;);
routes.IgnoreRoute(&lt;span style="color: #006080;"&gt;"sitemap"&lt;/span&gt;);
routes.IgnoreRoute(&lt;span style="color: #006080;"&gt;"sitemap.gz"&lt;/span&gt;);
routes.IgnoreRoute(&lt;span style="color: #006080;"&gt;"sitemap.xml"&lt;/span&gt;);
routes.IgnoreRoute(&lt;span style="color: #006080;"&gt;"sitemap.xml.gz"&lt;/span&gt;);
routes.IgnoreRoute(&lt;span style="color: #006080;"&gt;"google_sitemap.xml"&lt;/span&gt;);
routes.IgnoreRoute(&lt;span style="color: #006080;"&gt;"google_sitemap.xml.gz"&lt;/span&gt;);
routes.IgnoreRoute(&lt;span style="color: #006080;"&gt;"favicon.ico"&lt;/span&gt;);

&lt;span style="color: green;"&gt;//Rest of the code is ommited&lt;/span&gt;
}&lt;/pre&gt;&lt;/div&gt;I will update the list above as soon as I find a new URL that should be ignored, so stay tuned. As well you are welcome to contribute to this list by posting a comment.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-3857228549661646922?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/3857228549661646922/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=3857228549661646922" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/3857228549661646922?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/3857228549661646922?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2010/03/aspnet-mvc-best-practices-routes-to.html" title="ASP.NET MVC Best Practices – Routes to Ignore" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>2</thr:total></entry><entry gd:etag="W/&quot;A04AQHg4eip7ImA9WxBVGUQ.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-8563545483969035021</id><published>2010-02-14T13:04:00.002+02:00</published><updated>2010-02-24T10:25:41.632+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-24T10:25:41.632+02:00</app:edited><title>Some SharePoint 2010 Articles</title><content type="html">&lt;p&gt;Few months ago I have installed the beta version of the SharePoint 2010. The product looks really cool, although some of the requirements like: “must have Windows 2008 64bit” are really annoying.&lt;/p&gt;&lt;p&gt;In the past few weeks I have published some articles in one new site dedicated to SharePoint technologies called &lt;a href="http://www.sharepointmonitor.com/"&gt;SharepointMonitor.com&lt;/a&gt;. If somebody is interested, here is the list:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.sharepointmonitor.com/2010/01/building-approval-workflows-with-sharepoint-server-2010/"&gt;Building Approval Workflows with SharePoint Server 2010&lt;/a&gt; &lt;li&gt;&lt;a href="http://www.sharepointmonitor.com/2010/02/custom-workflows-sharepoint-designer-2010/"&gt;Building Custom Workflows using SharePoint Designer 2010&lt;/a&gt; &lt;li&gt;&lt;a href="http://www.sharepointmonitor.com/2010/01/difference-between-wss-3-0-and-moss-2007/"&gt;Difference between WSS 3.0 and MOSS 2007&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.sharepointmonitor.com/2010/02/getting-started-with-the-sharepoint-2010-excel-services"&gt;Getting Started with the SharePoint 2010 Excel Services&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;I have plans for several other articles, so stay tuned. I will update this post when something new comes out.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-8563545483969035021?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/8563545483969035021/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=8563545483969035021" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/8563545483969035021?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/8563545483969035021?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2010/02/some-sharepoint-2010-articles.html" title="Some SharePoint 2010 Articles" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;C0MGQn8-cSp7ImA9WxBVFk0.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-2565575548025617900</id><published>2010-01-17T01:06:00.002+02:00</published><updated>2010-02-19T19:43:43.159+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-19T19:43:43.159+02:00</app:edited><title>NHibernate: Display executed SQL at the bottom of an ASP.NET page (MVC or WebForms)</title><content type="html">&lt;p&gt;Almost every modern application that uses relational database is build on top of &lt;a href="http://en.wikipedia.org/wiki/Object-relational_mapping"&gt;ORM&lt;/a&gt; tool. The ORM tools can significantly decrease the efforts for interacting with the database, but unfortunately most of the developers are not familiar with the SQL code that is produced by the ORM tools. I’m not hiding that my favorite ORM is NHibernate. I’m using it since early beta, but from time to time even I’m surprised by the produced SQL. So, you need to monitor closely what SQL is executed. This blog post will describe one not widely used but very useful approach – the executed SQL will be displayed as a footer on any ASP.NET web page. It does not matter if the web page is using MVC or WebForms. Interested? Then continue reading.&lt;/p&gt;&lt;p&gt;Currently, there are several ways to display the SQL produced by NHibernate:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Database profiler tool – some of the modern RDBMS systems are coming with a profiler tool that can hook to the database engine and display the executed SQL. For example SQL Server comes with &lt;a href="http://msdn.microsoft.com/en-us/library/ms187929.aspx"&gt;SQL Server Profiler&lt;/a&gt;. Unfortunately the SQL Server Express edition is missing this tool. &lt;li&gt;&lt;a href="http://nhprof.com/"&gt;NHibernate Profiler&lt;/a&gt; – this is a third party tool that hooks to your application and monitors the NHibernate. Comes with cool WPF UI interface and lots of other features. Unfortunately at the time of writing you will need to purchase a license to use it. As well you will need to switch from your application to the tool after each action to monitor the produced SQL. &lt;li&gt;&lt;a href="http://logging.apache.org/log4net/index.html"&gt;Log4Net&lt;/a&gt; – you can configure the log4net library to save the produced SQL to a file for example. Unfortunately reading long files with SQL statements is too boring. Sometimes it is tricky to figure out the SQL executed as a result of single action. &lt;li&gt;Display the executed SQL at the bottom of an ASP.NET web page. The idea is to have an IHttpModule module that will inject the SQL code at the end of each request. This approach saves time, because the SQL is visible instantaneously after the action is executed. Unfortunately this trick works only for web applications.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;There are several ways to access the SQL that has been executed by NHibernate. I will use a &lt;a href="https://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/manipulatingdata.html#manipulatingdata-interceptors"&gt;NHibernate interceptor&lt;/a&gt;. The code for the interceptor looks like this:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; NHibernateSQLMonitor : EmptyInterceptor&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Init(Configuration config)&lt;br /&gt;    {&lt;br /&gt;        config.SetInterceptor(&lt;span class="kwrd"&gt;new&lt;/span&gt; NHibernateSQLMonitor());&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; StringBuilder mExecutedSQL = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder();&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ExecutedSQL&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; mExecutedSQL.ToString();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ClearExecutedSQL()&lt;br /&gt;    {&lt;br /&gt;        mExecutedSQL = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; NHibernate.SqlCommand.SqlString OnPrepareStatement(&lt;br /&gt;        NHibernate.SqlCommand.SqlString sql)&lt;br /&gt;    {&lt;br /&gt;        mExecutedSQL.AppendLine(sql.ToString());&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;base&lt;/span&gt;.OnPrepareStatement(sql);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt&lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The important method is &lt;strong&gt;OnPrepareStatement&lt;/strong&gt;. This method is invoked every time NHibernate executes SQL statement. The &lt;strong&gt;sql&lt;/strong&gt; parameter holds the SQL that will be executed.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Before using it, the interceptor must be registered. One possible way to do it is like this:&lt;/p&gt;&lt;pre class="csharpcode"&gt;NHibernate.Cfg.Configuration cfg = &lt;span class="kwrd"&gt;new&lt;/span&gt; NHibernate.Cfg.Configuration();&lt;br /&gt;NHibernateSQLMonitor.Init(cfg);&lt;br /&gt;&lt;br /&gt;ISessionFactory sessionFactory = cfg.BuildSessionFactory();&lt;/pre&gt;&lt;br /&gt;&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt&lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now everything is ready for our IHttpModule that will inject the executed SQL at the bottom of a web page. Here is the implementation:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; NHibernateSQLMonitorModule : IHttpModule&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Init(HttpApplication context)&lt;br /&gt;    {&lt;br /&gt;        context.PostRequestHandlerExecute += &lt;span class="kwrd"&gt;new&lt;/span&gt; EventHandler(&lt;br /&gt;  PostRequestHandlerExecute);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;void&lt;/span&gt; PostRequestHandlerExecute(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        HttpContext httpContext = ((HttpApplication)sender).Context;&lt;br /&gt;        HttpResponse response = httpContext.Response;&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; (response.StatusCode == 302)&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="rem"&gt;//Browser performs redirect. Do nothing.&lt;/span&gt;&lt;br /&gt;            &lt;span class="rem"&gt;//The executed SQL will be shown on the next page&lt;/span&gt;&lt;br /&gt;        }&lt;br /&gt;        &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (response.ContentType == &lt;span class="str"&gt;"text/html"&lt;/span&gt;)&lt;br /&gt;        {&lt;br /&gt;            response.Write(&lt;span class="str"&gt;"&amp;lt;hr&amp;gt;"&lt;/span&gt;);&lt;br /&gt;            response.Write(&lt;span class="str"&gt;"&amp;lt;b&amp;gt;SQL Executed by NHibernate&amp;lt;/b&amp;gt;"&lt;/span&gt;);&lt;br /&gt;            response.Write(&lt;span class="str"&gt;"&amp;lt;br&amp;gt;"&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;string&lt;/span&gt; executedSQL = NHibernateSQLMonitor.ExecutedSQL.Replace(&lt;br /&gt;   &lt;span class="str"&gt;"\n"&lt;/span&gt;, &lt;span class="str"&gt;"&amp;lt;br&amp;gt;"&lt;/span&gt;);&lt;br /&gt;            response.Write(executedSQL);&lt;br /&gt;&lt;br /&gt;            NHibernateSQLMonitor.ClearExecutedSQL();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Dispose()&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="rem"&gt;//Not required&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt&lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now there is one final step that should be done – the HttpModule needs to be registered in the config file of the application. To do it open the web.config file, find the &lt;strong&gt;&amp;lt;httpModules&amp;gt;&lt;/strong&gt; section (&lt;strong&gt;&amp;lt;modules&amp;gt; &lt;/strong&gt;if you are running IIS7) and place the following line there:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&amp;lt;add name=&lt;span class="str"&gt;"NHibernateSQLMonitor"&lt;br /&gt;&lt;/span&gt; type=&lt;span class="str"&gt;"Data.NHibernateSQLMonitorModule, Data"&lt;/span&gt;/&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt&lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;br /&gt;&lt;/style&gt;&lt;br /&gt;&lt;strong&gt;Data&lt;/strong&gt; is the assembly name where the &lt;strong&gt;NHibernateSQLMonitorModule&lt;/strong&gt; class is defined. Now everything is ready and if there are no compilation errors you should see something like this:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://lh4.ggpht.com/_2e9-Lk8T3Tg/S1JGWFsdafI/AAAAAAAAE4I/Pjg5_yR7ICE/s1600-h/image%5B8%5D.png"&gt;&lt;img style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_2e9-Lk8T3Tg/S1JGWu5q5VI/AAAAAAAAE4M/rbxmNGpsKlw/image_thumb%5B6%5D.png?imgmax=800" width="559" height="437" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;After adding new record, the page will look like this:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://lh4.ggpht.com/_2e9-Lk8T3Tg/S1JGXEDR0YI/AAAAAAAAE4Q/cLElac4LTf4/s1600-h/image%5B14%5D.png"&gt;&lt;img style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_2e9-Lk8T3Tg/S1JGX1meI4I/AAAAAAAAE4U/_YDmwzl1jJE/image_thumb%5B10%5D.png?imgmax=800" width="569" height="421" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;So, what about improvements:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Instead of using NHibernate interceptor for monitoring the executed SQL it is possible to display the output from the Log4Net. The log4net output contains the SQL parameter values which may be a great benefit. As you may have noticed, the values in the screenshot above are replaced by the ? character.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The current version uses static variable to hold the executed SQL. If there is more than one user interacting with the application, this will lead to some synchronization problems. For example, you can extend the NHibernateSQLMonitor class to use the ASP.NET Session store. This way the user will see only the SQL code executed as a result of his actions.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;P.S. This post was inspired long time ago after reading the &lt;a href="http://blog.codeville.net/"&gt;Steve Sanderson’s&lt;/a&gt; &lt;a href="http://www.amazon.com/Pro-ASP-NET-Framework-Steven-Sanderson/dp/1430210079/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1263681882&amp;amp;sr=8-1"&gt;Pro ASP.NET MVC Framework&lt;/a&gt;. He has a similar application that connects to Linq to SQL and displays the executed SQL.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-2565575548025617900?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/2565575548025617900/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=2565575548025617900" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/2565575548025617900?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/2565575548025617900?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2010/01/nhibernate-display-executed-sql-at.html" title="NHibernate: Display executed SQL at the bottom of an ASP.NET page (MVC or WebForms)" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/_2e9-Lk8T3Tg/S1JGWu5q5VI/AAAAAAAAE4M/rbxmNGpsKlw/s72-c/image_thumb%5B6%5D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CkMCRXc_fSp7ImA9WxBTE0o.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-7482160325282690878</id><published>2009-12-09T16:54:00.001+02:00</published><updated>2009-12-09T16:54:24.945+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-09T16:54:24.945+02:00</app:edited><title>eBay Architecture</title><content type="html">&lt;p&gt;Recently I was curious to find out how big sites like &lt;a href="http://www.ebay.com/"&gt;eBay&lt;/a&gt; are build and running. After a quick research I was able to find some quite interesting articles.&lt;/p&gt; &lt;p&gt;I was surprised to find out that eBay doesn't use transactions. As well they do not use foreign keys in their database (the same thing as the SharePoint_AdminContent database). It looks like this is the latest trend ;-)&lt;/p&gt; &lt;p&gt;If you are curious like me, take a look at the following:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.infoq.com/presentations/shoup-ebay-architectural-principles"&gt;Randy Shoup on eBay's Architectural Principles&lt;/a&gt;&lt;br&gt;&lt;a href="http://qconsf.com/sf2009/file?path=/QConSF2007/slides/public/RandyShoup_eBayArchPrinciples.pdf"&gt;eBay Architectural Strategies, Patterns, and Forces&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.se-radio.net/podcast/2008-09/episode-109-ebay039s-architecture-principles-randy-shoup"&gt;Software Engineering Radio: eBay's Architecture Principles with Randy Shoup&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.infoq.com/articles/ebay-scalability-best-practices"&gt;Scalability Best Practices: Lessons from eBay&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.infoq.com/interviews/dan-pritchett-ebay-architecture"&gt;Dan Pritchett on Architecture at eBay&lt;/a&gt;&lt;br&gt;&lt;a href="http://www.addsimplicity.com/adding_simplicity_an_engi/2006/11/you_scaled_your.html"&gt;You Scaled Your What?&lt;/a&gt;&lt;br&gt;&lt;a href="http://highscalability.com/blog/2008/5/27/ebay-architecture.html"&gt;High Scalability: eBay Architecture&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-7482160325282690878?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/7482160325282690878/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=7482160325282690878" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/7482160325282690878?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/7482160325282690878?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2009/12/ebay-architecture.html" title="eBay Architecture" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>2</thr:total></entry><entry gd:etag="W/&quot;C0IBQnw-eyp7ImA9WxBVFk0.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-2287795287986025262</id><published>2009-08-24T23:48:00.003+03:00</published><updated>2010-02-19T19:45:53.253+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-19T19:45:53.253+02:00</app:edited><title>jQuery FullCalendar and ASP.NET MVC</title><content type="html">&lt;p&gt;Recently I had to integrate &lt;a href="http://jquery.com/" target="_blank"&gt;jQuery&lt;/a&gt; &lt;a href="http://arshaw.com/fullcalendar/" target="_blank"&gt;FullCalendar&lt;/a&gt; into &lt;a href="http://www.asp.net/mvc/" target="_blank"&gt;ASP.NET MVC&lt;/a&gt; application. Up to now I was not able to find such an example, so I will try to provide one. I assume that you are familiar with ASP.NET MVC, jQuery and FullCalendar component, so I’m not going to introduce each technology.&lt;/p&gt;&lt;table border="0" cellspacing="0" cellpadding="2" width="747"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="200"&gt;&lt;a href="http://lh5.ggpht.com/_2e9-Lk8T3Tg/SpRD9AJEY2I/AAAAAAAAEZI/LKYj3chRRsE/s1600-h/image3%5B1%5D.png"&gt;&lt;img style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_2e9-Lk8T3Tg/SpL99kWvD9I/AAAAAAAAEZM/C7jlbob8JrU/image3_thumb.png?imgmax=800" width="194" height="272" /&gt;&lt;/a&gt; &lt;/td&gt;&lt;td valign="top" width="545"&gt;&lt;p&gt;I will use the default ASP.NET MVC Web Application template to create new project. Please, note that the jQuery is included by default, so there is no need to download and reference it.&lt;/p&gt;&lt;p&gt;The first step would be to place FullCalendar JavaScript and style-sheet files inside project’s Scripts and Content directory as shown in the picture.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Then we need to reference the files we just added to our project. I will do it by placing the following lines of code inside the &lt;strong&gt;&amp;lt;head&amp;gt;&lt;/strong&gt; section of &lt;strong&gt;Site.Master&lt;/strong&gt; file:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:ContentPlaceHolder&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="TitleContent"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;link&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;="../../Content/Site.css"&lt;/span&gt; &lt;span class="attr"&gt;rel&lt;/span&gt;&lt;span class="kwrd"&gt;="stylesheet"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/css"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;link&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;="../../Content/fullcalendar.css"&lt;/span&gt; &lt;span class="attr"&gt;rel&lt;/span&gt;&lt;span class="kwrd"&gt;="stylesheet"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/css"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;="../../Scripts/jquery-1.3.2.js"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &amp;lt;script src=&lt;span class="str"&gt;"../../Scripts/fullcalendar.js"&lt;/span&gt; type=&lt;span class="str"&gt;"text/javascript"&lt;/span&gt;&amp;gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;Now we are ready to use the calendar routines inside our views. How to do it? Just create a &lt;strong&gt;div&lt;/strong&gt; tag and render the calendar’s HTML code inside. Here is how to modify Home’s Index.aspx:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:Content&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="indexContent"&lt;/span&gt; &lt;span class="attr"&gt;ContentPlaceHolderID&lt;/span&gt;&lt;span class="kwrd"&gt;="MainContent"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;       $(document).ready(&lt;span class="kwrd"&gt;function&lt;/span&gt;() {&lt;br /&gt;           $(&lt;span class="str"&gt;'#calendar'&lt;/span&gt;).fullCalendar({&lt;br /&gt;               events: &lt;span class="str"&gt;"/Home/CalendarData"&lt;/span&gt;&lt;br /&gt;           });&lt;br /&gt;       });  &lt;br /&gt;   &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="calendar"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:Content&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;The code above will render the calendar’s HTML inside a div with id=”calendar”. The calendar data will be delivered by invoking the following URL: &lt;em&gt;/Home/CalendarData&lt;/em&gt;. This corresponds to &lt;em&gt;CalendarData&lt;/em&gt; method from the &lt;em&gt;Home&lt;/em&gt; controller. This controller is supposed to return the data in &lt;a href="http://www.json.org/" target="_blank"&gt;Json&lt;/a&gt; format. Here is a sample implementation:&lt;/p&gt;&lt;pre class="csharpcode"&gt;    [HandleError]&lt;br /&gt;   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; HomeController : Controller&lt;br /&gt;   {&lt;br /&gt;       &lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult CalendarData()&lt;br /&gt;       {&lt;br /&gt;           IList&amp;lt;CalendarDTO&amp;gt; tasksList = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;CalendarDTO&amp;gt;();&lt;br /&gt;&lt;br /&gt;           tasksList.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; CalendarDTO&lt;br /&gt;           {&lt;br /&gt;               id = 1,&lt;br /&gt;               title = &lt;span class="str"&gt;"Google search"&lt;/span&gt;,&lt;br /&gt;               start = ToUnixTimespan(DateTime.Now),&lt;br /&gt;               end = ToUnixTimespan(DateTime.Now.AddHours(4)),&lt;br /&gt;               url = &lt;span class="str"&gt;"www.google.com"&lt;/span&gt;&lt;br /&gt;           });&lt;br /&gt;           tasksList.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; CalendarDTO&lt;br /&gt;           {&lt;br /&gt;               id = 1,&lt;br /&gt;               title = &lt;span class="str"&gt;"Bing search"&lt;/span&gt;,&lt;br /&gt;               start = ToUnixTimespan(DateTime.Now.AddDays(1)),&lt;br /&gt;               end = ToUnixTimespan(DateTime.Now.AddDays(1).AddHours(4)),&lt;br /&gt;               url = &lt;span class="str"&gt;"www.bing.com"&lt;/span&gt;&lt;br /&gt;           });&lt;br /&gt;&lt;br /&gt;           &lt;span class="kwrd"&gt;return&lt;/span&gt; Json(tasksList);&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;long&lt;/span&gt; ToUnixTimespan(DateTime date)&lt;br /&gt;       {&lt;br /&gt;           TimeSpan tspan = date.ToUniversalTime().Subtract(&lt;br /&gt;    &lt;span class="kwrd"&gt;new&lt;/span&gt; DateTime(1970, 1, 1, 0, 0, 0));&lt;br /&gt;&lt;br /&gt;           &lt;span class="kwrd"&gt;return&lt;/span&gt; (&lt;span class="kwrd"&gt;long&lt;/span&gt;)Math.Truncate(tspan.TotalSeconds);&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       &lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Index()&lt;br /&gt;       {&lt;br /&gt;           &lt;span class="kwrd"&gt;return&lt;/span&gt; View();&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       &lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult About()&lt;br /&gt;       {&lt;br /&gt;           &lt;span class="kwrd"&gt;return&lt;/span&gt; View();&lt;br /&gt;       }&lt;br /&gt;   }&lt;/pre&gt;&lt;p&gt;The code above creates two calendar entries called “Google search” and “Bing search”. Everything should be pretty simple, except the stuff around ToUnixTimespan routine.&lt;/p&gt;&lt;p&gt;There is well known problem with serialization of dates in Json format. There is no strict standard, so there are several approaches to this problem. For example, take a look &lt;a href="http://weblogs.asp.net/bleroy/archive/2008/01/18/dates-and-json.aspx" target="_blank"&gt;here&lt;/a&gt;. The implementation adopted by Microsoft was not recognized by FullCalendar, so I had to introduce the ToUnixTimespan routine. Basically, this routine returns the seconds after 1/1/1970.&lt;/p&gt;&lt;p&gt;Because of the above, you should notice that the &lt;em&gt;start&lt;/em&gt; and &lt;em&gt;end&lt;/em&gt; dates are represented as int:&lt;/p&gt;&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CalendarDTO&lt;br /&gt;   {&lt;br /&gt;       &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; id { get; set; }&lt;br /&gt;       &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; title { get; set; }&lt;br /&gt;       &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;long&lt;/span&gt; start { get; set; }&lt;br /&gt;       &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;long&lt;/span&gt; end { get; set; }&lt;br /&gt;       &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; url { get; set; }&lt;br /&gt;   }&lt;/pre&gt;&lt;p&gt;If you have done everything correct, the final result will be&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_2e9-Lk8T3Tg/SpMFwMPT42I/AAAAAAAAEZA/A8gHejD-nOE/s1600-h/image%5B15%5D.png"&gt;&lt;img style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_2e9-Lk8T3Tg/SpMFw5LJmbI/AAAAAAAAEZE/Gx21nDq8QXc/image_thumb%5B9%5D.png?imgmax=800" width="655" height="643" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;Enjoy!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-2287795287986025262?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/2287795287986025262/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=2287795287986025262" title="14 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/2287795287986025262?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/2287795287986025262?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2009/08/jquery-fullcalendar-and-aspnet-mvc.html" title="jQuery FullCalendar and ASP.NET MVC" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/_2e9-Lk8T3Tg/SpL99kWvD9I/AAAAAAAAEZM/C7jlbob8JrU/s72-c/image3_thumb.png?imgmax=800" height="72" width="72" /><thr:total>14</thr:total></entry><entry gd:etag="W/&quot;D0cBQXo-fip7ImA9WB5RFE4.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-4509996852463838718</id><published>2007-06-21T16:36:00.000+03:00</published><updated>2007-06-21T17:10:50.456+03:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-06-21T17:10:50.456+03:00</app:edited><title>Anti-development methodologies</title><content type="html">Software industry is growing constantly and development methodologies are following the same trend. Internet is full with shiny articles describing each methodology and all the benefit. Most of the people I'm talking are bored when they hear stuff like this. If you are like them, don't miss &lt;a href="http://www.scottberkun.com/blog/2007/asshole-driven-development/"&gt;this&lt;/a&gt; article. A friend of mine just send me the link. Also, check out the comments. All of them are about dummy development practices. Some of the titles are cynical, but there is a lot of truth in each line.&lt;br /&gt;Enjoy!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-4509996852463838718?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/4509996852463838718/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=4509996852463838718" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/4509996852463838718?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/4509996852463838718?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2007/06/software-industry-is-growing-constantly.html" title="Anti-development methodologies" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CEUDRn87cCp7ImA9WBFUFks.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-4197451598643969719</id><published>2007-04-27T10:57:00.000+03:00</published><updated>2007-04-27T11:24:37.108+03:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-04-27T11:24:37.108+03:00</app:edited><title>BrainStorm Rocks</title><content type="html">Yesterday was a great day. My team called &lt;a href="http://imaginecup.com/MyStuff/MyTeam.aspx?TeamID=169"&gt;BrainStorm&lt;/a&gt; won the local round of Microsoft's &lt;a href="http://imaginecup.com/"&gt;Imagine Cup 2007&lt;/a&gt; competition in the area of software design.&lt;br /&gt;Our project with the code name &lt;a href="http://bookvar.blogspot.com/"&gt;Bookvar&lt;/a&gt; will compete in the finals this year in Seoul, Korea. This was possible, because of the remarkable team I'm part of. Right now I can't find appropriate words to describe them, but as one of the jury said: "I had the chance to watch these young motivated and smart people". It's a great pleasure to work with each one of them.&lt;br /&gt;Although we managed to win the local round, there is still much work to be done. Lucky for us, the finals are after 3 months.&lt;br /&gt;Check out &lt;a href="http://xman892.blogspot.com/2007/04/imagine-cup-bulgaria-07-summary.html"&gt;this&lt;/a&gt; post from Ruslan Trifonov if you want to see some pictures from the event. Ruslan was member of the jury.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-4197451598643969719?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/4197451598643969719/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=4197451598643969719" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/4197451598643969719?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/4197451598643969719?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2007/04/brainstorm-rocks.html" title="BrainStorm Rocks" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total></entry><entry gd:etag="W/&quot;CkcNQn04fCp7ImA9WBFQF0U.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-3272932276865588531</id><published>2007-03-13T11:55:00.000+02:00</published><updated>2007-03-13T12:01:33.334+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-03-13T12:01:33.334+02:00</app:edited><title>Grand Prix Racing Online</title><content type="html">Last week I was chatting with an old friend of mine - Vladimir Alexandrov. I was surprised to find out that he is driving the &lt;a href="http://www.gpro.se"&gt;Grand Prix Racing Online&lt;/a&gt; site. Basically this is a F1 on-line simulator. If you are a F1 fan you will appreciate what Vladimir and his team is doing. The site is completely free and guess what - no advertisements are present.&lt;br /&gt;There are some interesting issues about the implementation and hosting, but because of security I can not share them.&lt;br /&gt;Good luck Vlado, and continue with the great job.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-3272932276865588531?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/3272932276865588531/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=3272932276865588531" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/3272932276865588531?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/3272932276865588531?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2007/03/grand-prix-racing-online.html" title="Grand Prix Racing Online" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DkMMQHw9cSp7ImA9WBFQF0w.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-8521084598645771051</id><published>2007-03-12T17:34:00.000+02:00</published><updated>2007-03-12T17:48:01.269+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-03-12T17:48:01.269+02:00</app:edited><title>NHibernate and triggers</title><content type="html">Recently I was asked from a college of mine, about the following exception in application based on SQL Server 2005 and NHibernate :&lt;br /&gt;&lt;blockquote&gt;[NHibernate.AdoNet.TooManyRowsAffectedException] {"Unexpected row count: 2; expected: 1"} NHibernate.AdoNet.TooManyRowsAffectedException&lt;/blockquote&gt;&lt;br /&gt;After a quick investigation the problem was obvious - the exception raises when a row from a table is updated and the row has fired a trigger which executes an update statement.&lt;br /&gt;I have faced with this problem since early beta of NHibernate (0.8.4 as far as I can remember). Till now the only solution I have found is to use &lt;strong&gt;SET NOCOUNT&lt;/strong&gt; to stop the message that shows the number of rows affected by a Transact-SQL statement from being returned as part of the results.&lt;br /&gt;Just place SET NOCOUNT ON before the UPDATE statement inside the trigger and then after the UPDATE statement place SET NOCOUNT OFF. This will solve the problem.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-8521084598645771051?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/8521084598645771051/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=8521084598645771051" title="13 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/8521084598645771051?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/8521084598645771051?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2007/03/nhibernate-and-triggers.html" title="NHibernate and triggers" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>13</thr:total></entry><entry gd:etag="W/&quot;DkUCR347eSp7ImA9WBFQF0w.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-7133943764220490636</id><published>2007-03-12T17:29:00.000+02:00</published><updated>2007-03-12T17:44:26.001+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-03-12T17:44:26.001+02:00</app:edited><title>ASP.NET Web Part editor in pop-up dialog</title><content type="html">Last hour I was wondering how to host a ASP.NET Web Part editor control inside a pop-up dialog. I was lucky to find &lt;a href="http://markitup.com/Posts/Post.aspx?postId=a20e70f2-7eb1-40b6-b498-5bf4cb7b6edd"&gt;this&lt;/a&gt; implementation. It is based on some tricks, but resolves the problem.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-7133943764220490636?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/7133943764220490636/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=7133943764220490636" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/7133943764220490636?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/7133943764220490636?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2007/03/aspnet-web-part-editor-in-pop-up-dialog.html" title="ASP.NET Web Part editor in pop-up dialog" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total></entry><entry gd:etag="W/&quot;DEcASHgyfSp7ImA9WBBVFk8.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-1928824890732386770</id><published>2006-12-20T16:46:00.000+02:00</published><updated>2006-12-20T16:47:29.695+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2006-12-20T16:47:29.695+02:00</app:edited><title>First Bulgarian .NET Book is here</title><content type="html">Second volume from the first Bulgarian book about .NET is out. You can download free copy from &lt;a href="http://www.devbg.org/dotnetbook"&gt;here&lt;/a&gt;. Printed version will be available after a month.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-1928824890732386770?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/1928824890732386770/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=1928824890732386770" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/1928824890732386770?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/1928824890732386770?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2006/12/first-bulgarian-net-book-is-here.html" title="First Bulgarian .NET Book is here" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DE4BQX48eSp7ImA9WBBQF0g.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-7197725586332312014</id><published>2006-11-17T11:46:00.000+02:00</published><updated>2006-11-17T11:49:10.071+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2006-11-17T11:49:10.071+02:00</app:edited><title>Windows Forms data binding and notification of changed properties</title><content type="html">&lt;p&gt;Yesterday a college of mine asked me a question: "How to refresh TextBox control in Windows forms application binded to a property of object, when the property change its value?". The solution is very simple, but according to me not very well documented (at least in books I read).&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Solution: Provide event named &lt;em&gt;PropertyName&lt;/em&gt;Changed, where &lt;em&gt;PropertyName&lt;/em&gt; is the name of property binded to the TextBox. During the binding process, the text box inspects binded object for event with the mentioned signature and binds to it. The sample code looks like this:&lt;/p&gt;&lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof1251\uc1 \deff0{\fonttbl{\f0\fnil\fcharset204\fprq1 Courier New;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0??;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;??\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;??\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;??\red192\green192\blue192;}??\fs20 \cf2 public\cf0  \cf2 class\cf0  \cf10 Customer\par ??\cf0 \{\par ??    \cf2 private\cf0  \cf2 string\cf0  mName;\par ??\par ??    \cf2 public\cf0  \cf2 string\cf0  Name\par ??    \{\par ??        \cf2 get\cf0  \{ \cf2 return\cf0  mName; \}\par ??        \cf2 set\par ??\cf0         \{\par ??            mName = \cf2 value\cf0 ;\par ??            \cf2 if\cf0  (NameChanged != \cf2 null\cf0 )\par ??            \{\par ??                NameChanged(\cf2 this\cf0 , \cf10 EventArgs\cf0 .Empty);\par ??            \}\par ??        \}\par ??    \}\par ??\par ??    \cf2 public\cf0  \cf2 event\cf0  \cf10 EventHandler\cf0  NameChanged;\par ??\}\par ??\par ??Customer cust = \cf2 new\cf0  Customer();\par ??textBox1.DataBindings.Add(\cf13 "Text"\cf0 , cust, \cf13 "Name"\cf0 );\par ??} --&gt;&lt;br /&gt;&lt;div style="BACKGROUND: white;font-family:courier new;font-size:10pt;color:black;"   &gt;&lt;pre style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:teal;"&gt;Customer&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;{&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; mName;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; Name&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;get&lt;/span&gt; { &lt;span style="color:blue;"&gt;return&lt;/span&gt; mName; }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;set&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            mName = &lt;span style="color:blue;"&gt;value&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;if&lt;/span&gt; (NameChanged != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                NameChanged(&lt;span style="color:blue;"&gt;this&lt;/span&gt;, &lt;span style="color:teal;"&gt;EventArgs&lt;/span&gt;.Empty);&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;event&lt;/span&gt; &lt;span style="color:teal;"&gt;EventHandler&lt;/span&gt; NameChanged;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;}&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;Customer cust = &lt;span style="color:blue;"&gt;new&lt;/span&gt; Customer();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;textBox1.DataBindings.Add(&lt;span style="color:maroon;"&gt;"Text"&lt;/span&gt;, cust, &lt;span style="color:maroon;"&gt;"Name"&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;&lt;/pre&gt;&lt;/div&gt;Another possible solution is to remove and add binding of the text box to the object. You can write general routine to loop through each control for a given form and remove-add binding. This is nasty solution of course.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-7197725586332312014?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/7197725586332312014/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=7197725586332312014" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/7197725586332312014?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/7197725586332312014?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2006/11/windows-forms-data-binding-and.html" title="Windows Forms data binding and notification of changed properties" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>4</thr:total></entry><entry gd:etag="W/&quot;CEEAQX08fCp7ImA9WBBRFks.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-115799569610052451</id><published>2006-09-11T20:21:00.000+03:00</published><updated>2006-11-04T19:50:40.374+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2006-11-04T19:50:40.374+02:00</app:edited><title>Cool conference in Bulgaria</title><content type="html">&lt;a href="http://www.devreach.com/"&gt;DevReach&lt;/a&gt; - one of the most exiting conferences about Microsoft technologies in Bulgaria is coming. According to the program, some of the world leading industry speakers will present quite interesting lectures. Hope we will meet there.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-115799569610052451?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/115799569610052451/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=115799569610052451" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115799569610052451?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115799569610052451?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2006/09/cool-conference-in-bulgaria.html" title="Cool conference in Bulgaria" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CEEAQXwycCp7ImA9WBBRFks.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-115799496346969013</id><published>2006-09-11T20:01:00.000+03:00</published><updated>2006-11-04T19:50:40.298+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2006-11-04T19:50:40.298+02:00</app:edited><title>Google toolbar 4</title><content type="html">This morning I was amazed! A few minutes after turning on my PC a small balloon appeared. The message in the balloon was something about Google toolbar update. Who cares, was my first reaction. But when the update was finished I was surprised to learn that &lt;strong&gt;LONG WAITING FEATURES LIKE ACCESSING BOOKMARKS FROM ANY COMPUTER&lt;/strong&gt; are already present. Believe me - this is like a elixir of life for me. I'm using one PC at work, one PC at home and one laptop. Managing bookmarks in situation like this is almost nightmare. In the past there were some other decision of this problem, but none of them was so elegant as Google toolbar. BTW, Microsoft are developing the same service, but as far as I know this feature is still in beta.&lt;br /&gt;The other features I like are SpellCheck and Translate. If you are inspired, install the toolbar from &lt;a href="http://toolbar.google.com/T4/index_xp.html"&gt;here&lt;/a&gt; for WinXP and IE. Enjoy!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-115799496346969013?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/115799496346969013/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=115799496346969013" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115799496346969013?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115799496346969013?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2006/09/google-toolbar-4.html" title="Google toolbar 4" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>2</thr:total></entry><entry gd:etag="W/&quot;CEEAQXw5fyp7ImA9WBBRFks.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-115735061566417978</id><published>2006-09-04T09:15:00.000+03:00</published><updated>2006-11-04T19:50:40.227+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2006-11-04T19:50:40.227+02:00</app:edited><title>ADO.NET Entity Framework ContextObject and ASP.NET application</title><content type="html">Last month Microsoft published first CTP of ADO.NET Entity Framework. For more info - look &lt;a href="http://szahariev.blogspot.com/2006/08/adonet-vnext-ctp-is-out.html"&gt;here&lt;/a&gt;. Although Microsoft is still planning integration between Entity Framework and ASP.NET, I want to show you how to handle ADO.NET Entity Framewrok context object in ASP.NET application. This post is inspired from &lt;a href="http://szahariev.blogspot.com/2006/07/nhibernate-session-management.html"&gt;NHibernate session management&lt;/a&gt;.&lt;br /&gt;The idea is simple: Context object will be stored in ASP.NET session and after the request HTTPModule will free it. I'm using ASP.NET session instead of ASP.NET context to further extend this example to support session per application transaction strategy. If you are wondering what is "session per application transaction" take a look at &lt;a href="http://szahariev.blogspot.com/2006/07/nhibernate-session-management.html"&gt;NHibernate session management&lt;/a&gt;. Here is the code of the implementation:&lt;br /&gt;&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof1251\uc1 \deff0{\fonttbl{\f0\fnil\fcharset204\fprq1 Courier New;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0??;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;??\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;??\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;??\red192\green192\blue192;}??\fs20 \cf2 public\cf0  \cf2 class\cf0  \cf10 ContextManager\cf0 &amp;lt;T&amp;gt;\cf2 where\cf0  T: \cf10 ObjectContext\cf0 , \cf2 new\cf0 ()\par ??\{\par ??    \cf2 public\cf0  \cf2 static\cf0  T ObjectContext\par ??    \{\par ??        \cf2 get\par ??\cf0         \{\par ??            T resultContext;\par ??\par ??            \cf2 if\cf0  (\cf10 HttpContext\cf0 .Current.Items.Contains(\par ??                \cf10 ContextConst\cf0 .CONTEXT_OBJECT_SESSION_KEY))\par ??            \{\par ??                resultContext =\par ??                    (T)\cf10 HttpContext\cf0 .Current.Items[\par ??                        \cf10 ContextConst\cf0 .CONTEXT_OBJECT_SESSION_KEY];\par ??            \}\par ??            \cf2 else\par ??\cf0             \{\par ??                resultContext = \cf2 new\cf0  T();\par ??                \cf10 HttpContext\cf0 .Current.Items[\cf10 ContextConst\cf0 .CONTEXT_OBJECT_SESSION_KEY] = \par ??                    resultContext;\par ??            \}\par ??\par ??            \cf2 return\cf0  resultContext;\par ??        \}\par ??    \}\par ??\par ??    \cf2 public\cf0  \cf2 static\cf0  \cf2 bool\cf0  isActiveObjectContext\par ??    \{\par ??        \cf2 get\par ??\cf0         \{ \par ??            \cf2 return\cf0  \cf10 HttpContext\cf0 .Current.Items.Contains(\par ??                \cf10 ContextConst\cf0 .CONTEXT_OBJECT_SESSION_KEY);\par ??        \}\par ??    \}\par ?? \}\par ??}&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; &lt;span style="color: teal;"&gt;ContextManager&lt;/span&gt;&amp;lt;T&amp;gt;&lt;span style="color: blue;"&gt;where&lt;/span&gt; T: &lt;span style="color: teal;"&gt;ObjectContext&lt;/span&gt;, &lt;span style="color: blue;"&gt;new&lt;/span&gt;()&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;{&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; T ObjectContext&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;get&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; T resultContext;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt; (&lt;span style="color: teal;"&gt;HttpContext&lt;/span&gt;.Current.Items.Contains(&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: teal;"&gt;ContextConst&lt;/span&gt;.CONTEXT_OBJECT_SESSION_KEY))&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; resultContext =&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; (T)&lt;span style="color: teal;"&gt;HttpContext&lt;/span&gt;.Current.Items[&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: teal;"&gt;ContextConst&lt;/span&gt;.CONTEXT_OBJECT_SESSION_KEY];&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;else&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; resultContext = &lt;span style="color: blue;"&gt;new&lt;/span&gt; T();&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: teal;"&gt;HttpContext&lt;/span&gt;.Current.Items[&lt;span style="color: teal;"&gt;ContextConst&lt;/span&gt;.CONTEXT_OBJECT_SESSION_KEY] = &lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; resultContext;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; resultContext;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;bool&lt;/span&gt; isActiveObjectContext&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;get&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: teal;"&gt;HttpContext&lt;/span&gt;.Current.Items.Contains(&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: teal;"&gt;ContextConst&lt;/span&gt;.CONTEXT_OBJECT_SESSION_KEY);&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;}&lt;/pre&gt;&lt;/div&gt;&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof1251\uc1 \deff0{\fonttbl{\f0\fnil\fcharset204\fprq1 Courier New;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0??;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;??\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;??\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;??\red192\green192\blue192;}??\fs20 \cf2 public\cf0  \cf2 class\cf0  \cf10 ContextHttpModule\cf0  : \cf10 IHttpModule\cf0  \par ??\{\par ??\cf2     #region\cf0  IHttpModule Members\par ??\par ??    \cf2 public\cf0  \cf2 void\cf0  Init(\cf10 HttpApplication\cf0  context)\par ??    \{\par ??        context.EndRequest += \cf2 new\cf0  \cf10 EventHandler\cf0 (OnEndRequest);\par ??    \}\par ??\par ??    \cf2 public\cf0  \cf2 void\cf0  Dispose()\par ??    \{\par ??        \cf11 //Intentionaly not implemented\par ??\cf0     \}\par ??\par ??    \cf2 public\cf0  \cf2 void\cf0  OnEndRequest(\cf10 Object\cf0  sender, \cf10 EventArgs\cf0  e)\par ??    \{\par ??        \cf2 if\cf0  (\cf10 HttpContext\cf0 .Current.Items.Contains(\cf10 ContextConst\cf0 .CONTEXT_OBJECT_SESSION_KEY))\par ??        \{\par ??            \cf10 ObjectContext\cf0  contextObject = \par ??                (\cf10 ObjectContext\cf0 )\cf10 HttpContext\cf0 .Current.Items[\par ??                    \cf10 ContextConst\cf0 .CONTEXT_OBJECT_SESSION_KEY];\par ??            \par ??            contextObject.Dispose();\par ??        \}\par ??    \}\par ??\par ??\cf2     #endregion\par ??\cf0 \}\par ??}&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; &lt;span style="color: teal;"&gt;ContextHttpModule&lt;/span&gt; : &lt;span style="color: teal;"&gt;IHttpModule&lt;/span&gt; &lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;{&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #region&lt;/span&gt; IHttpModule Members&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; Init(&lt;span style="color: teal;"&gt;HttpApplication&lt;/span&gt; context)&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; context.EndRequest += &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: teal;"&gt;EventHandler&lt;/span&gt;(OnEndRequest);&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; Dispose()&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;//Intentionaly not implemented&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; OnEndRequest(&lt;span style="color: teal;"&gt;Object&lt;/span&gt; sender, &lt;span style="color: teal;"&gt;EventArgs&lt;/span&gt; e)&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt; (&lt;span style="color: teal;"&gt;HttpContext&lt;/span&gt;.Current.Items.Contains(&lt;span style="color: teal;"&gt;ContextConst&lt;/span&gt;.CONTEXT_OBJECT_SESSION_KEY))&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: teal;"&gt;ObjectContext&lt;/span&gt; contextObject = &lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;span style="color: teal;"&gt;ObjectContext&lt;/span&gt;)&lt;span style="color: teal;"&gt;HttpContext&lt;/span&gt;.Current.Items[&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: teal;"&gt;ContextConst&lt;/span&gt;.CONTEXT_OBJECT_SESSION_KEY];&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; contextObject.Dispose();&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #endregion&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof1251\uc1 \deff0{\fonttbl{\f0\fnil\fcharset204\fprq1 Courier New;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0??;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;??\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;??\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;??\red192\green192\blue192;}??\fs20 \cf2 internal\cf0  \cf2 class\cf0  \cf10 ContextConst\par ??\cf0 \{\par ??    \cf2 public\cf0  \cf2 const\cf0  \cf2 string\cf0  CONTEXT_OBJECT_SESSION_KEY =\par ??        \cf13 "ContextConst.CONTEXT_OBJECT_SESSION_KEY"\cf0 ;\par ??\}\par ??}&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;internal&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; &lt;span style="color: teal;"&gt;ContextConst&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;{&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;const&lt;/span&gt; &lt;span style="color: blue;"&gt;string&lt;/span&gt; CONTEXT_OBJECT_SESSION_KEY =&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: maroon;"&gt;"ContextConst.CONTEXT_OBJECT_SESSION_KEY"&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Now, lets look how the code above can be used. First lets make some corrections to web.config file:&lt;br /&gt;&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset204\fprq1 Courier New;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0??;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;??\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;??\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;??\red192\green192\blue192;}??\fs20 \cf2 &amp;lt;\cf13 connectionStrings\cf2 &amp;gt;\par ??  &amp;lt;\cf13 add\cf2  \cf6 name\cf2 =\cf0 "\cf2 Duwamish7Model.Duwamish7\cf0 "\cf2  \par ??       \cf6 connectionString\cf2 =\cf0 "\cf2 metadata=C:\\Temp\\ContextObject\\Model;\par ??          mapping=C:\\Temp\\ContextObject\\Model;\par ??          provider=System.Data.SqlClient;\par ??          provider connection string=\cf6 &amp;amp;quot;\cf2 Data Source=ns-server;\par ??          Initial Catalog=Duwamish7;Integrated Security=True\cf6 &amp;amp;quot;\cf0 "\par ??\cf2     \cf6 providerName\cf2 =\cf0 "\cf2 System.Data.Mapping\cf0 "\cf2  /&amp;gt;\par ??&amp;lt;/\cf13 connectionStrings\cf2 &amp;gt;\par ??}&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon;"&gt;connectionStrings&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: maroon;"&gt;add&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;name&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Duwamish7Model.Duwamish7&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style="color: red;"&gt;connectionString&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;metadata=C:\Temp\ContextObject\Model;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mapping=C:\Temp\ContextObject\Model;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; provider=System.Data.SqlClient;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; provider connection string=&lt;/span&gt;&lt;span style="color: red;"&gt;&amp;amp;quot;&lt;/span&gt;&lt;span style="color: blue;"&gt;Data Source=ns-server;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Initial Catalog=Duwamish7;Integrated Security=True&lt;/span&gt;&lt;span style="color: red;"&gt;&amp;amp;quot;&lt;/span&gt;"&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="color: red;"&gt;providerName&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;System.Data.Mapping&lt;/span&gt;"&lt;span style="color: blue;"&gt; /&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon;"&gt;connectionStrings&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset204\fprq1 Courier New;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0??;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;??\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;??\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;??\red192\green192\blue192;}??\fs20 \cf2 &amp;lt;\cf13 httpModules\cf2 &amp;gt;\par ??  &amp;lt;\cf13 add\cf2  \cf6 name\cf2 =\cf0 "\cf2 ContextObjectManager\cf0 "\par ??\cf2        \cf6 type\cf2 =\cf0 "\cf2 ObjectContextManager.ContextHttpModule, ObjectContextManager\cf0 "\cf2 /&amp;gt;\par ??&amp;lt;/\cf13 httpModules\cf2 &amp;gt;\par ??}&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon;"&gt;httpModules&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: maroon;"&gt;add&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;name&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;ContextObjectManager&lt;/span&gt;"&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style="color: red;"&gt;type&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;ObjectContextManager.ContextHttpModule, ObjectContextManager&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon;"&gt;httpModules&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;Having all of the above done, we can write somethig like this:&lt;br /&gt;&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof1251\uc1 \deff0{\fonttbl{\f0\fnil\fcharset204\fprq1 Courier New;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0??;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;??\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;??\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;??\red192\green192\blue192;}??\fs20 \cf10 Duwamish7\cf0  db = \cf10 ContextManager\cf0 &amp;lt;\cf10 Duwamish7\cf0 &amp;gt;.ObjectContext;\par ??\par ??\cf10 Query\cf0 &amp;lt;\cf10 Authors\cf0 &amp;gt; query = db.GetQuery&amp;lt;\cf10 Authors\cf0 &amp;gt;(\par ??    \cf13 "SELECT VALUE a FROM Authors AS a WHERE a.PKId &amp;gt; 144"\cf0 );\par ??\par ??Repeater1.DataSource = query;\par ??Repeater1.DataBind();\par ??}&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: teal;"&gt;Duwamish7&lt;/span&gt; db = &lt;span style="color: teal;"&gt;ContextManager&lt;/span&gt;&amp;lt;&lt;span style="color: teal;"&gt;Duwamish7&lt;/span&gt;&amp;gt;.ObjectContext;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: teal;"&gt;Query&lt;/span&gt;&amp;lt;&lt;span style="color: teal;"&gt;Authors&lt;/span&gt;&amp;gt; query = db.GetQuery&amp;lt;&lt;span style="color: teal;"&gt;Authors&lt;/span&gt;&amp;gt;(&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: maroon;"&gt;"SELECT VALUE a FROM Authors AS a WHERE a.PKId &amp;gt; 144"&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;Repeater1.DataSource = query;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;Repeater1.DataBind();&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;P.S. The code above is not tested for concurrency problems.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-115735061566417978?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/115735061566417978/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=115735061566417978" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115735061566417978?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115735061566417978?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2006/09/adonet-entity-framework-contextobject.html" title="ADO.NET Entity Framework ContextObject and ASP.NET application" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CEEAQX8-fyp7ImA9WBBRFks.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-115729161993565785</id><published>2006-09-03T16:48:00.000+03:00</published><updated>2006-11-04T19:50:40.157+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2006-11-04T19:50:40.157+02:00</app:edited><title>WCF and WS Eventing</title><content type="html">WCF (aka Indigo) is the latest communication technology from Microsoft (still in beta). Although there are a lot of goodies in this technology, something really useful for me is missing - implementation of WS Eventing. If you are wondering why - &lt;a href="http://www.longhornblogs.com/robert/articles/VSLive_DonBox.aspx"&gt;this article&lt;/a&gt; gives the answer. Fortunately there is already non-Microsoft implementation. Read this &lt;a href="http://www.codeproject.com/useritems/WSEventing.asp"&gt;article&lt;/a&gt; if you are interested.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-115729161993565785?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/115729161993565785/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=115729161993565785" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115729161993565785?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115729161993565785?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2006/09/wcf-and-ws-eventing.html" title="WCF and WS Eventing" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CEEAQX47eCp7ImA9WBBRFks.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-115640514286033089</id><published>2006-08-24T10:27:00.000+03:00</published><updated>2006-11-04T19:50:40.000+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2006-11-04T19:50:40.000+02:00</app:edited><title>Finally it is true!</title><content type="html">Yesterday, PFC Levski Sofia did it. The team had succeeded to qualify for the UEFA champions league group stage for the first time in Bulgarian football history. Although I'm fan of the &lt;a href="http://www.cska.bg/"&gt;CSKA Sofia&lt;/a&gt; the success of Levski makes me happy. More info - &lt;a href="http://www.uefa.com/competitions/UCL/FixturesResults/Round=2356/match=84632/Report=RP.html"&gt;here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-115640514286033089?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/115640514286033089/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=115640514286033089" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115640514286033089?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115640514286033089?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2006/08/finally-it-is-true.html" title="Finally it is true!" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CEEHSHc4fSp7ImA9WBBRFks.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-115634808600526927</id><published>2006-08-23T18:36:00.000+03:00</published><updated>2006-11-04T19:50:39.935+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2006-11-04T19:50:39.935+02:00</app:edited><title>Microsoft SQL Server and Ad-Hock queries optimization</title><content type="html">Yesterday I was surprised to learn that Microsoft SQL Server 2005 makes behind the scene parameterization of ad-hock queries. For example, lets have the following query:&lt;br /&gt;&lt;blockquote&gt;SELECT ID, Name FROM Article WHERE Price &gt; 100&lt;/blockquote&gt;&lt;br /&gt;SQL Server 2005 will replace constant literal values (100 in this example) by variables and this way query plan will be reuses for all queries similar to&lt;blockquote&gt;SELECT ID, Name FROM Article WHERE Price &gt; @p1&lt;/blockquote&gt;&lt;br /&gt;Not all of the ad-hock queries can be parameterized. If you are interested read &lt;a href="http://www.microsoft.com/technet/prodtechnol/sql/2005/recomp.mspx"&gt;this&lt;/a&gt; article.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-115634808600526927?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/115634808600526927/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=115634808600526927" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115634808600526927?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115634808600526927?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2006/08/microsoft-sql-server-and-ad-hock.html" title="Microsoft SQL Server and Ad-Hock queries optimization" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CEEHSHY9fSp7ImA9WBBRFks.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-115634437256870276</id><published>2006-08-23T17:31:00.000+03:00</published><updated>2006-11-04T19:50:39.865+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2006-11-04T19:50:39.865+02:00</app:edited><title>Attribute based transaction management and NHibernate</title><content type="html">In my previous post about &lt;a href="http://szahariev.blogspot.com/2006/07/nhibernate-session-management.html"&gt;NHibernate session management&lt;/a&gt; I presented a session per request strategy for session management in ASP.NET application. I will extend this example to show you how to declaratively manage transactions via attributes. Take a look at the GenericDAO.Save method:&lt;br /&gt;&lt;br /&gt;&lt;div style="BACKGROUND: white;font-family:Courier New;font-size:10pt;color:black;"   &gt;&lt;pre style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; Save(T entity)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;{&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;bool&lt;/span&gt; manageTransaction = ! orm.isActiveTransaction;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;if&lt;/span&gt; (manageTransaction)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        orm.BeginTransaction(&lt;span style="color:teal;"&gt;IsolationLevel&lt;/span&gt;.ReadCommitted);&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;try&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        orm.session.SaveOrUpdate(entity);&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;if&lt;/span&gt; (manageTransaction)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            orm.CommitTransaction();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;span style="color:blue;"&gt;catch&lt;/span&gt;(&lt;span style="color:teal;"&gt;Exception&lt;/span&gt; e)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;if&lt;/span&gt; (manageTransaction)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            orm.RollbackTransaction();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;throw&lt;/span&gt; e;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }            &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Almost 90% of the code is for transaction management. It will be nice if we can write something like:&lt;br /&gt;&lt;br /&gt;&lt;div style="BACKGROUND: white;font-family:Courier New;font-size:10pt;color:black;"   &gt;&lt;pre style="MARGIN: 0px"&gt;[&lt;span style="color:teal;"&gt;Transaction&lt;/span&gt;(&lt;span style="color:teal;"&gt;IsolationLevel&lt;/span&gt;.ReadCommitted)]&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; Save(T entity)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;{&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    mOrm.session.SaveOrUpdate(entity);&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    mOrm.session.Flush();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;To achieve this, I will use &lt;a href="http://www.springframework.net"&gt;Spring.NET&lt;/a&gt; to intercept method call of the DAO. Before method marked with TransactionAttribute is executed a transaction will be started and then committed after method is executed. Although .NET provides solution for intercepting method calls via ContextBoundObject, I will use Spring.NET because this way my DAO object must implement just one interface instead of inheriting from ContextBoundObject.&lt;br /&gt;Lets begin with the implementation. First I will declare the attribute used to mark transaction sensitive methods:&lt;br /&gt;&lt;br /&gt;&lt;div style="BACKGROUND: white;font-family:Courier New;font-size:10pt;color:black;"   &gt;&lt;pre style="MARGIN: 0px"&gt;[&lt;span style="color:teal;"&gt;AttributeUsage&lt;/span&gt;(&lt;span style="color:teal;"&gt;AttributeTargets&lt;/span&gt;.Method)]&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:teal;"&gt;TransactionAttribute&lt;/span&gt; : &lt;span style="color:teal;"&gt;Attribute&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;{&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:teal;"&gt;IsolationLevel&lt;/span&gt; mIsolationLevel;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; TransactionAttribute()&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        mIsolationLevel = &lt;span style="color:teal;"&gt;IsolationLevel&lt;/span&gt;.ReadCommitted;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; TransactionAttribute(&lt;span style="color:teal;"&gt;IsolationLevel&lt;/span&gt; aIsolation)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        mIsolationLevel = aIsolation;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:teal;"&gt;IsolationLevel&lt;/span&gt; isolationLevel&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;get&lt;/span&gt; { &lt;span style="color:blue;"&gt;return&lt;/span&gt; mIsolationLevel; }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;set&lt;/span&gt; { mIsolationLevel = &lt;span style="color:blue;"&gt;value&lt;/span&gt;; }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Now I will decrare the class responsible for starting and committing transactions. There are a lot of specific issues about method interception and Spring.NET so if you are not familiar with them read the documentation about &lt;a href="http://www.springframework.net"&gt;Spring.NET&lt;/a&gt;. The class looks like:&lt;br /&gt;&lt;br /&gt;&lt;div style="BACKGROUND: white;font-family:Courier New;font-size:10pt;color:black;"   &gt;&lt;pre style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:teal;"&gt;TransactionAroundAdvice&lt;/span&gt; : &lt;span style="color:teal;"&gt;IMethodInterceptor&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;{&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:teal;"&gt;OrmManager&lt;/span&gt; mOrm;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; TransactionAroundAdvice()&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        mOrm = &lt;span style="color:teal;"&gt;OrmManagerFactory&lt;/span&gt;.GetInstance();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:teal;"&gt;TransactionAttribute&lt;/span&gt; GetTransactionAttribute(&lt;span style="color:teal;"&gt;MethodInfo&lt;/span&gt; aMethod)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;object&lt;/span&gt;[] attributes = aMethod.GetCustomAttributes(&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;typeof&lt;/span&gt;(&lt;span style="color:teal;"&gt;TransactionAttribute&lt;/span&gt;), &lt;span style="color:blue;"&gt;true&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;if&lt;/span&gt; (attributes.Length != 1)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:green;"&gt;//TODO: Throw more meaningfull exception and message&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;throw&lt;/span&gt; &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:teal;"&gt;Exception&lt;/span&gt;(&lt;span style="color:maroon;"&gt;"Transaction Attribute is missing"&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;return&lt;/span&gt; (&lt;span style="color:teal;"&gt;TransactionAttribute&lt;/span&gt;)attributes[0];&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;object&lt;/span&gt; Invoke(&lt;span style="color:teal;"&gt;IMethodInvocation&lt;/span&gt; invocation)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;bool&lt;/span&gt; manageTransaction = ! mOrm.isActiveTransaction;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;if&lt;/span&gt; (manageTransaction)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:teal;"&gt;TransactionAttribute&lt;/span&gt; transactionAttribute =&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                GetTransactionAttribute(invocation.Method);&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            mOrm.BeginTransaction(transactionAttribute.isolationLevel);&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:green;"&gt;//TODO: Find way to compare isolation level from TransactionAttribute and&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:green;"&gt;//current active transaction if manageTransaction == false&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;object&lt;/span&gt; returnValue;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;try&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            returnValue = invocation.Proceed();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;if&lt;/span&gt; (manageTransaction)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                mOrm.CommitTransaction();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        }&lt;span style="color:blue;"&gt;catch&lt;/span&gt;(&lt;span style="color:teal;"&gt;Exception&lt;/span&gt; e)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;if&lt;/span&gt; (manageTransaction)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                mOrm.RollbackTransaction();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;if&lt;/span&gt; ((e &lt;span style="color:blue;"&gt;is&lt;/span&gt; &lt;span style="color:teal;"&gt;TargetInvocationException&lt;/span&gt;) &amp;amp;&amp; (e.InnerException != &lt;span style="color:blue;"&gt;null&lt;/span&gt;))&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                &lt;span style="color:green;"&gt;//Because when AOP is enables, method is invoked via reflection&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                &lt;span style="color:green;"&gt;//TargetInvocationException is thrown. This exception is most likely&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                &lt;span style="color:green;"&gt;//to confuse application developer, so it is removed&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                &lt;span style="color:blue;"&gt;throw&lt;/span&gt; e.InnerException;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;else&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                &lt;span style="color:blue;"&gt;throw&lt;/span&gt; e;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        }            &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;return&lt;/span&gt; returnValue;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;When a method marked with TransactionAttribute is intercepted then Invoke method from TransactionAroundAdvice class is called. Now lets see how our DAO class looks like when transaction management code is removed:&lt;br /&gt;&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof1251\uc1 \deff0{\fonttbl{\f0\fnil\fcharset204\fprq1 Courier New;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0??;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;??\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;??\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;??\red192\green192\blue192;}??\fs20 \cf2 public\cf0  \cf2 class\cf0  \cf10 AttributeEnabledDAO\cf0 &amp;lt;T&amp;gt;: \cf10 IDAO\cf0 &amp;lt;T&amp;gt;\par ??\{\par ??    \cf2 public\cf0  AttributeEnabledDAO()\par ??    \{\par ??        mOrm = \cf10 OrmManagerFactory\cf0 .GetInstance();\par ??    \}\par ??\par ??    \cf2 private\cf0  \cf10 OrmManager\cf0  mOrm;\par ??\par ??\cf2     #region\cf0  IDAO Members\par ??\par ??    \cf2 public\cf0  T Load(\cf2 object\cf0  id)\par ??    \{\par ??        \cf2 return\cf0  (T) mOrm.session.Load(\cf2 typeof\cf0 (T), id);\par ??    \}\par ??\par ??    [\cf10 Transaction\cf0 (\cf10 IsolationLevel\cf0 .ReadCommitted)]\par ??    \cf2 public\cf0  \cf2 void\cf0  Save(T entity)\par ??    \{\par ??        mOrm.session.SaveOrUpdate(entity);\par ??        mOrm.session.Flush();\par ??    \}\par ??\par ??\cf2     #endregion\par ??\cf0 \}\par ??}&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; &lt;span style="color: teal;"&gt;AttributeEnabledDAO&lt;/span&gt;&amp;lt;T&amp;gt;: &lt;span style="color: teal;"&gt;IDAO&lt;/span&gt;&amp;lt;T&amp;gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;{&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; AttributeEnabledDAO()&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; mOrm = &lt;span style="color: teal;"&gt;OrmManagerFactory&lt;/span&gt;.GetInstance();&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: teal;"&gt;OrmManager&lt;/span&gt; mOrm;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #region&lt;/span&gt; IDAO Members&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; T Load(&lt;span style="color: blue;"&gt;object&lt;/span&gt; id)&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; (T) mOrm.session.Load(&lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(T), id);&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="color: teal;"&gt;Transaction&lt;/span&gt;(&lt;span style="color: teal;"&gt;IsolationLevel&lt;/span&gt;.ReadCommitted)]&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; Save(T entity)&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; mOrm.session.SaveOrUpdate(entity);&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; mOrm.session.Flush();&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #endregion&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Much more simple. Example of using AttributeEnabledDAO is given bellow:&lt;br /&gt;&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof1251\uc1 \deff0{\fonttbl{\f0\fnil\fcharset204\fprq1 Courier New;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0??;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;??\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;??\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;??\red192\green192\blue192;}??\fs20 \cf10 ProxyFactory\cf0  articleDAOFactory = \cf2 new\cf0  \cf10 ProxyFactory\cf0 (\par ??    \cf2 new\cf0  \cf10 AttributeEnabledDAO\cf0 &amp;lt;\cf10 Article\cf0 &amp;gt;());\par ??\par ??articleDAOFactory.AddAdvisor(\cf2 new\cf0  \cf10 DefaultPointcutAdvisor\cf0 (\par ??    \cf2 new\cf0  \cf10 AttributeMatchMethodPointcut\cf0 (\cf2 typeof\cf0 (\cf10 TransactionAttribute\cf0 )),\par ??    \cf2 new\cf0  \cf10 TransactionAroundAdvice\cf0 ()));\par ??\par ??\cf10 IDAO\cf0 &amp;lt;\cf10 Article\cf0 &amp;gt; articleDao;\par ??\cf2 lock\cf0  (synchObject)\par ??\{\par ??    articleDao = (\cf10 IDAO\cf0 &amp;lt;\cf10 Article\cf0 &amp;gt;) articleDAOFactory.GetProxy();\par ??\}\par ??\par ??\cf10 Article\cf0  article = articleDao.Load(1);\par ??article.Name = \cf13 "Paracetamol"\cf0 ;\par ??article.SalePrice = rnd.NextDouble();\par ??articleDao.Save(article);\par ??}&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: teal;"&gt;ProxyFactory&lt;/span&gt; articleDAOFactory = &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: teal;"&gt;ProxyFactory&lt;/span&gt;(&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: teal;"&gt;AttributeEnabledDAO&lt;/span&gt;&amp;lt;&lt;span style="color: teal;"&gt;Article&lt;/span&gt;&amp;gt;());&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;articleDAOFactory.AddAdvisor(&lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: teal;"&gt;DefaultPointcutAdvisor&lt;/span&gt;(&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: teal;"&gt;AttributeMatchMethodPointcut&lt;/span&gt;(&lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(&lt;span style="color: teal;"&gt;TransactionAttribute&lt;/span&gt;)),&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: teal;"&gt;TransactionAroundAdvice&lt;/span&gt;()));&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: teal;"&gt;IDAO&lt;/span&gt;&amp;lt;&lt;span style="color: teal;"&gt;Article&lt;/span&gt;&amp;gt; articleDao;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;lock&lt;/span&gt; (synchObject)&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;{&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; articleDao = (&lt;span style="color: teal;"&gt;IDAO&lt;/span&gt;&amp;lt;&lt;span style="color: teal;"&gt;Article&lt;/span&gt;&amp;gt;) articleDAOFactory.GetProxy();&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;}&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: teal;"&gt;Article&lt;/span&gt; article = articleDao.Load(1);&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;article.Name = &lt;span style="color: maroon;"&gt;"Paracetamol"&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;article.SalePrice = rnd.NextDouble();&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;articleDao.Save(article);&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-115634437256870276?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/115634437256870276/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=115634437256870276" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115634437256870276?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115634437256870276?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2006/08/attribute-based-transaction-management.html" title="Attribute based transaction management and NHibernate" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CEEHSHkyfyp7ImA9WBBRFks.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-115571506542581251</id><published>2006-08-16T10:48:00.000+03:00</published><updated>2006-11-04T19:50:39.797+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2006-11-04T19:50:39.797+02:00</app:edited><title>ADO.NET vNext CTP is out</title><content type="html">Microsoft has just released &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=B68F6F53-EC87-4122-B1C8-EE24A043BF72&amp;displaylang=en"&gt;ADO.NET vNext CTP&lt;/a&gt;. This CTP includes the preview build of the long waiting ADO.NET Entity Framework. This Entity Framework is Microsoft's ORM tool. If you are wondering what is ORM tool take a look at my post about  &lt;br /&gt;&lt;a href="http://szahariev.blogspot.com/2006/07/nhibernate-session-management.html"&gt;NHibernate session management&lt;/a&gt;.&lt;br /&gt;Presentation with features of Entity Data Model can be found &lt;a href="http://blogs.msdn.com/dataaccess/archive/2006/06/22/642260.aspx"&gt;here&lt;/a&gt;. If somehow Link* technologies looks messy for you, taka a look at &lt;a href="http://channel9.msdn.com/Showpost.aspx?postid=202138"&gt;this presentation&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-115571506542581251?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/115571506542581251/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=115571506542581251" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115571506542581251?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115571506542581251?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2006/08/adonet-vnext-ctp-is-out.html" title="ADO.NET vNext CTP is out" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CEEHSHk5fCp7ImA9WBBRFks.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-115484437786703974</id><published>2006-08-06T09:06:00.000+03:00</published><updated>2006-11-04T19:50:39.724+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2006-11-04T19:50:39.724+02:00</app:edited><title>Querying Microsoft SQL Server trace files</title><content type="html">Have you ever wanted to be able to query saved SQL Server profiler trace files (*.trc)? Yes! Then you need to use &lt;a href="http://msdn2.microsoft.com/en-us/library/ms188425.aspx"&gt;fn_trace_gettable&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-115484437786703974?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/115484437786703974/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=115484437786703974" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115484437786703974?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115484437786703974?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2006/08/querying-microsoft-sql-server-trace.html" title="Querying Microsoft SQL Server trace files" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CEEHSHsyfSp7ImA9WBBRFks.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-115476824225777873</id><published>2006-08-05T11:48:00.000+03:00</published><updated>2006-11-04T19:50:39.595+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2006-11-04T19:50:39.595+02:00</app:edited><title>Interview with Anders Hejlsberg</title><content type="html">Take a look at &lt;a href="http://channel9.msdn.com/Showpost.aspx?postid=159952"&gt;this&lt;/a&gt; interview with Anders Hejlsberg. It's not about a future technology. It's about himself. Watching this video you will find answers to questions like: Why Anders left Borland and joined Microsoft? What is the secret of his success? Anders talks for the time working on projects like: Turbo Pascal, Delphi, C#. Enjoy!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-115476824225777873?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/115476824225777873/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=115476824225777873" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115476824225777873?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115476824225777873?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2006/08/interview-with-anders-hejlsberg.html" title="Interview with Anders Hejlsberg" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CEEHSHs5fip7ImA9WBBRFks.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-115476293537521370</id><published>2006-08-05T10:19:00.000+03:00</published><updated>2006-11-04T19:50:39.526+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2006-11-04T19:50:39.526+02:00</app:edited><title>Mocking static methods</title><content type="html">Yes, the title is correct. Mocking static methods in .NET is possible with &lt;a href="http://www.typemock.com/"&gt;TypeMock&lt;/a&gt; library. There is no need to redesign you classes just to test them. In fact there is no need to write additional code to your classes. This is possible because TypeMock uses profiler's API to handle execution of methods and creation of classes. For a list of features look &lt;a href="http://www.typemock.com/Features.htm"&gt;here&lt;/a&gt;.&lt;br /&gt;Using TypeMock is pretty easy. In my previous post about &lt;a href="http://szahariev.blogspot.com/2006/07/nhibernate-session-management.html"&gt;NHibernate session management&lt;/a&gt; I'm using a static method to create appropriate session manager (take a look at GenericDAO constructor). The test of the constructor may be something like:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="BACKGROUND: white;font-family:Courier New;font-size:10pt;color:black;"   &gt;&lt;pre style="MARGIN: 0px"&gt;[&lt;span style="color:teal;"&gt;TestFixture&lt;/span&gt;]&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:teal;"&gt;GenericDAOTest&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;{&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    [&lt;span style="color:teal;"&gt;SetUp&lt;/span&gt;]&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; InitTest()&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:teal;"&gt;MockManager&lt;/span&gt;.Init();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:green;"&gt;//ormManagerMock = MockManager.Mock(typeof(PerRequestWebManager));&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        ormManagerFactory = &lt;span style="color:teal;"&gt;MockManager&lt;/span&gt;.Mock(&lt;span style="color:blue;"&gt;typeof&lt;/span&gt;(&lt;span style="color:teal;"&gt;OrmManagerFactory&lt;/span&gt;));&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:green;"&gt;//private Mock ormManagerMock;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:teal;"&gt;Mock&lt;/span&gt; ormManagerFactory;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:teal;"&gt;GenericDAO&lt;/span&gt;&amp;lt;&lt;span style="color:teal;"&gt;Article&lt;/span&gt;&amp;gt; articleDAO;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    [&lt;span style="color:teal;"&gt;TearDown&lt;/span&gt;]&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; FinalizeTest()&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:teal;"&gt;MockManager&lt;/span&gt;.ClearAll();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    [Test]&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; TestDAOConstructor()&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        ormManagerFactory.ExpectAndReturn(&lt;span style="color:maroon;"&gt;"GetInstance"&lt;/span&gt;,&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:teal;"&gt;PerRequestWebManager&lt;/span&gt;());&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        articleDAO = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:teal;"&gt;GenericDAO&lt;/span&gt;&amp;lt;&lt;span style="color:teal;"&gt;Article&lt;/span&gt;&amp;gt;();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:teal;"&gt;MockManager&lt;/span&gt;.Verify();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;}&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;Although TypeMock is powerful and easy to use library, there are some disadvantages. For example in the free version, when the test is started for first time, a popup dialog appears and invites you to buy the product. Also not all of the .NET types can be mocked (for more information take a look at &lt;a href="http://www.typemock.com/community/viewtopic.php?t=200"&gt;this&lt;/a&gt; thread).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-115476293537521370?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/115476293537521370/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=115476293537521370" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115476293537521370?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115476293537521370?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2006/08/mocking-static-methods.html" title="Mocking static methods" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CUMDSH08cCp7ImA9WxBVFks.&quot;"><id>tag:blogger.com,1999:blog-31061699.post-115385127998541264</id><published>2006-07-25T21:08:00.001+03:00</published><updated>2010-02-20T12:57:59.378+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-20T12:57:59.378+02:00</app:edited><title>NHibernate Session Management</title><content type="html">I'm big fan of &lt;a href="http://www.hibernate.org/343.html"&gt;NHibernate&lt;/a&gt; since early beta. Unfortunately this tool is not very popular among .NET developers, so I'm planning to blog a lot about this framework. For those of you who don't know, NHibernate is ORM (Object-Relational-Mapping) tool. Basically ORM tools are used to "persist" C# objects into RDBMS system. More detail explanation of ORM tools is available &lt;a href="http://www.agiledata.org/essays/mappingObjects.html"&gt;here&lt;/a&gt;.&lt;br /&gt;NHibernate handles loading/saving objects to RDBMS via it's own implementation of session object. Until now, I'm familiar with 3 ways for handling NHibernate sessions:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;create session per each database operation - session is created before and destroyed after each operation with database. This is very ineffective way, because some features like lazy loading are unavailable. Also including several database operations in transaction is impossible.&lt;/li&gt;&lt;li&gt;create session per each request - session is created before and destroyed after each HTTP request. This is my favorite strategy, because it is effective and very easy for implementation. I'll give example for possible implementation in this post.&lt;/li&gt;&lt;li&gt;create session per each application transaction - session is created before and destroyed after each application transaction. Example for application transaction is adding invoice with invoice items.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;So, lets begin with the implementation of session per request strategy. If you are reading this post you are most likely a developer and probably as most developers prefer to read source code instead of boring documentation. So I'll explain all of the classes in brief and will post full source code. First I'll declare a base abstract class for all of the session strategies. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof1251\uc1 \deff0{\fonttbl{\f0\fnil\fcharset204\fprq1 Courier New;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0??;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;??\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;??\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;??\red192\green192\blue192;}??\fs20 \cf2 public\cf0  \cf2 abstract\cf0  \cf2 class\cf0  \cf10 OrmManager\par ??\cf0 \{\par ??    \cf2 public\cf0  OrmManager()\par ??    \{\par ??    \}\par ??\par ??    \cf2 static\cf0  NHibernate.Cfg.\cf10 Configuration\cf0  mConfiguration = \cf2 null\cf0 ;\par ??    \cf2 static\cf0  \cf2 volatile\cf0  \cf10 ISessionFactory\cf0  mSessionFactory = \cf2 null\cf0 ;\par ??    \cf2 static\cf0  \cf2 object\cf0  mFactorySyncObject = \cf2 new\cf0  \cf2 object\cf0 ();\par ??\par ??    \cf2 public\cf0  \cf2 abstract\cf0  \cf10 ISession\cf0  session\par ??    \{\par ??        \cf2 get\cf0 ;\par ??    \}\par ??\par ??    \cf2 public\cf0  \cf10 IDbConnection\cf0  sessionConnection\par ??    \{\par ??        \cf2 get\cf0  \{ \cf2 return\cf0  session.Connection; \}\par ??    \}\par ??\par ??    \cf2 public\cf0  \cf10 ISession\cf0  NewSession()\par ??    \{\par ??        \cf10 ISessionFactory\cf0  sessionFactory = GetSessionFactory();\par ??\par ??        \cf2 return\cf0  sessionFactory.OpenSession();\par ??    \}\par ??\par ??    \cf2 public\cf0  \cf2 abstract\cf0  \cf2 bool\cf0  isActiveSession\par ??    \{\par ??        \cf2 get\cf0 ;\par ??    \}\par ??\par ??    \cf2 public\cf0  \cf2 abstract\cf0  \cf2 void\cf0  closeSession();\par ??\par ??    \cf2 private\cf0  \cf2 const\cf0  \cf2 string\cf0  HBM_ASSEMBLY_NAME_SECTION = \cf13 "HbmAssemblyName"\cf0 ;\par ??    \par ??    \cf2 private\cf0  \cf10 ISessionFactory\cf0  GetSessionFactory()\par ??    \{\par ??        \cf2 if\cf0  (mSessionFactory == \cf2 null\cf0 )\par ??        \{\par ??            \cf2 lock\cf0  (mFactorySyncObject)\par ??            \{\par ??                \cf2 if\cf0  (mSessionFactory == \cf2 null\cf0 )\par ??                \{\par ??                    \cf2 string\cf0  hbmAssemblyName =\par ??                        \cf10 ConfigurationManager\cf0 .AppSettings[HBM_ASSEMBLY_NAME_SECTION];\par ??\par ??                    mConfiguration = \cf2 new\cf0  NHibernate.Cfg.\cf10 Configuration\cf0 ();\par ??                    mConfiguration.AddAssembly(hbmAssemblyName);\par ??\par ??                    mSessionFactory = mConfiguration.BuildSessionFactory();\par ??                \}\par ??            \}\par ??        \}\par ??\par ??        \cf2 return\cf0  mSessionFactory;\par ??    \}\par ??\par ??    \cf2 public\cf0  \cf2 void\cf0  BeginTransaction(\cf10 IsolationLevel\cf0  isolation)\par ??    \{\par ??        session.BeginTransaction(isolation);\par ??    \}\par ??\par ??    \cf2 public\cf0  \cf2 void\cf0  CommitTransaction()\par ??    \{\par ??        session.Transaction.Commit();\par ??    \}\par ??\par ??    \cf2 public\cf0  \cf2 void\cf0  RollbackTransaction()\par ??    \{\par ??        session.Transaction.Rollback();\par ??    \}\par ??\par ??    \cf2 public\cf0  \cf2 bool\cf0  isActiveTransaction\par ??    \{\par ??        \cf2 get\par ??\cf0         \{\par ??            \cf2 return\cf0  ((session.Transaction != \cf2 null\cf0 ) &amp;&amp;\par ??                (!session.Transaction.WasCommitted) &amp;amp;amp;amp;&amp;\par ??                (!session.Transaction.WasRolledBack));\par ??        \}\par ??    \}\par ??\}\par ??} --&gt;&lt;br /&gt;&lt;div style="BACKGROUND: white;font-family:Courier New;font-size:10pt;color:black;"   &gt;&lt;pre style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;abstract&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:teal;"&gt;OrmManager&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;{&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; OrmManager()&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;static&lt;/span&gt; NHibernate.Cfg.&lt;span style="color:teal;"&gt;Configuration&lt;/span&gt; mConfiguration = &lt;span style="color:blue;"&gt;null&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;volatile&lt;/span&gt; &lt;span style="color:teal;"&gt;ISessionFactory&lt;/span&gt; mSessionFactory = &lt;span style="color:blue;"&gt;null&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;object&lt;/span&gt; mFactorySyncObject = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:blue;"&gt;object&lt;/span&gt;();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;abstract&lt;/span&gt; &lt;span style="color:teal;"&gt;ISession&lt;/span&gt; session&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;get&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:teal;"&gt;IDbConnection&lt;/span&gt; sessionConnection&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;get&lt;/span&gt; { &lt;span style="color:blue;"&gt;return&lt;/span&gt; session.Connection; }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:teal;"&gt;ISession&lt;/span&gt; NewSession()&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:teal;"&gt;ISessionFactory&lt;/span&gt; sessionFactory = GetSessionFactory();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;return&lt;/span&gt; sessionFactory.OpenSession();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;abstract&lt;/span&gt; &lt;span style="color:blue;"&gt;bool&lt;/span&gt; isActiveSession&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;get&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;abstract&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; closeSession();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;const&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; HBM_ASSEMBLY_NAME_SECTION = &lt;span style="color:maroon;"&gt;"HbmAssemblyName"&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:teal;"&gt;ISessionFactory&lt;/span&gt; GetSessionFactory()&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;if&lt;/span&gt; (mSessionFactory == &lt;span style="color:blue;"&gt;null&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;lock&lt;/span&gt; (mFactorySyncObject)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                &lt;span style="color:blue;"&gt;if&lt;/span&gt; (mSessionFactory == &lt;span style="color:blue;"&gt;null&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                    &lt;span style="color:blue;"&gt;string&lt;/span&gt; hbmAssemblyName =&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                        &lt;span style="color:teal;"&gt;ConfigurationManager&lt;/span&gt;.AppSettings[HBM_ASSEMBLY_NAME_SECTION];&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                    mConfiguration = &lt;span style="color:blue;"&gt;new&lt;/span&gt; NHibernate.Cfg.&lt;span style="color:teal;"&gt;Configuration&lt;/span&gt;();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                    mConfiguration.AddAssembly(hbmAssemblyName);&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                    mSessionFactory = mConfiguration.BuildSessionFactory();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;return&lt;/span&gt; mSessionFactory;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; BeginTransaction(&lt;span style="color:teal;"&gt;IsolationLevel&lt;/span&gt; isolation)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        session.BeginTransaction(isolation);&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; CommitTransaction()&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        session.Transaction.Commit();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; RollbackTransaction()&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        session.Transaction.Rollback();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;bool&lt;/span&gt; isActiveTransaction&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;get&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;return&lt;/span&gt; ((session.Transaction != &lt;span style="color:blue;"&gt;null&lt;/span&gt;) &amp;amp;&amp;amp;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                (!session.Transaction.WasCommitted) &amp;amp;&amp;amp;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                (!session.Transaction.WasRolledBack));&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Next, I'll implement the class responsible for session per request management. The following class implements IHttpModule so, we can handle end of the request and close any open sessions.&lt;/p&gt;&lt;p&gt;&lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof1251\uc1 \deff0{\fonttbl{\f0\fnil\fcharset204\fprq1 Courier New;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0??;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;??\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;??\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;??\red192\green192\blue192;}??\fs20 \cf2 public\cf0  \cf2 class\cf0  \cf10 PerRequestWebManager\cf0  : \cf10 OrmManager\cf0 , \cf10 IHttpModule\par ??\cf0 \{\par ??    \cf2 public\cf0  PerRequestWebManager()\par ??    \{\par ??    \}\par ??\par ??    \cf2 private\cf0  \cf2 const\cf0  \cf2 string\cf0  NHIBERNATE_SESSION_KEY = \cf13 "NHIBERNATE_SESSION"\cf0 ;\par ??\par ??    \cf2 public\cf0  \cf2 override\cf0  \cf10 ISession\cf0  session\par ??    \{\par ??        \cf2 get\par ??\cf0         \{\par ??            \cf10 ISession\cf0  resultSession;\par ??\par ??            \cf2 if\cf0  (\cf10 HttpContext\cf0 .Current.Items.Contains(NHIBERNATE_SESSION_KEY))\par ??            \{\par ??                resultSession =\par ??                    (\cf10 ISession\cf0 )\cf10 HttpContext\cf0 .Current.Items[NHIBERNATE_SESSION_KEY];\par ??            \}\par ??            \cf2 else\par ??\cf0             \{\par ??                resultSession = NewSession();\par ??                \cf10 HttpContext\cf0 .Current.Items[NHIBERNATE_SESSION_KEY] = resultSession;\par ??            \}\par ??\par ??            \cf2 return\cf0  resultSession;\par ??        \}\par ??    \}\par ??\par ??    \cf2 public\cf0  \cf2 override\cf0  \cf2 bool\cf0  isActiveSession\par ??    \{\par ??        \cf2 get\cf0  \{ \cf2 return\cf0  \cf10 HttpContext\cf0 .Current.Items.Contains(NHIBERNATE_SESSION_KEY); \}\par ??    \}\par ??\par ??    \cf2 public\cf0  \cf2 override\cf0  \cf2 void\cf0  closeSession()\par ??    \{\par ??        \cf2 if\cf0  (isActiveSession == \cf2 true\cf0 )\par ??        \{\par ??            \cf2 if\cf0  (isActiveTransaction == \cf2 true\cf0 )\par ??            \{\par ??                RollbackTransaction();\par ??            \}\par ??\par ??            session.Close();\par ??            \cf10 HttpContext\cf0 .Current.Items.Remove(NHIBERNATE_SESSION_KEY);\par ??        \}\par ??    \}\par ??\par ??\cf2     #region\cf0  IHttpModule\par ??\par ??    \cf2 public\cf0  \cf2 void\cf0  Init(\cf10 HttpApplication\cf0  context)\par ??    \{\par ??        context.EndRequest += \cf2 new\cf0  \cf10 EventHandler\cf0 (OnEndRequest);\par ??    \}\par ??\par ??    \cf2 public\cf0  \cf2 void\cf0  Dispose()\par ??    \{\par ??        \cf11 //Intentionaly not implemented\par ??\cf0     \}\par ??\par ??    \cf2 public\cf0  \cf2 void\cf0  OnEndRequest(\cf10 Object\cf0  sender, \cf10 EventArgs\cf0  e)\par ??    \{\par ??        closeSession();\par ??    \}\par ??\par ??\cf2     #endregion\par ??\cf0 \}\par ??} --&gt;&lt;br /&gt;&lt;div style="BACKGROUND: white;font-family:Courier New;font-size:10pt;color:black;"   &gt;&lt;pre style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:teal;"&gt;PerRequestWebManager&lt;/span&gt; : &lt;span style="color:teal;"&gt;OrmManager&lt;/span&gt;, &lt;span style="color:teal;"&gt;IHttpModule&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;{&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; PerRequestWebManager()&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;const&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; NHIBERNATE_SESSION_KEY = &lt;span style="color:maroon;"&gt;"NHIBERNATE_SESSION"&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;override&lt;/span&gt; &lt;span style="color:teal;"&gt;ISession&lt;/span&gt; session&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;get&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:teal;"&gt;ISession&lt;/span&gt; resultSession;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;if&lt;/span&gt; (&lt;span style="color:teal;"&gt;HttpContext&lt;/span&gt;.Current.Items.Contains(NHIBERNATE_SESSION_KEY))&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                resultSession =&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                    (&lt;span style="color:teal;"&gt;ISession&lt;/span&gt;)&lt;span style="color:teal;"&gt;HttpContext&lt;/span&gt;.Current.Items[NHIBERNATE_SESSION_KEY];&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;else&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                resultSession = NewSession();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                &lt;span style="color:teal;"&gt;HttpContext&lt;/span&gt;.Current.Items[NHIBERNATE_SESSION_KEY] = resultSession;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;return&lt;/span&gt; resultSession;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;override&lt;/span&gt; &lt;span style="color:blue;"&gt;bool&lt;/span&gt; isActiveSession&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;get&lt;/span&gt; { &lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:teal;"&gt;HttpContext&lt;/span&gt;.Current.Items.Contains(NHIBERNATE_SESSION_KEY); }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;override&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; closeSession()&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;if&lt;/span&gt; (isActiveSession == &lt;span style="color:blue;"&gt;true&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;if&lt;/span&gt; (isActiveTransaction == &lt;span style="color:blue;"&gt;true&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                RollbackTransaction();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            session.Close();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:teal;"&gt;HttpContext&lt;/span&gt;.Current.Items.Remove(NHIBERNATE_SESSION_KEY);&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;    #region&lt;/span&gt; IHttpModule&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; Init(&lt;span style="color:teal;"&gt;HttpApplication&lt;/span&gt; context)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        context.EndRequest += &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:teal;"&gt;EventHandler&lt;/span&gt;(OnEndRequest);&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; Dispose()&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:green;"&gt;//Intentionaly not implemented&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; OnEndRequest(&lt;span style="color:teal;"&gt;Object&lt;/span&gt; sender, &lt;span style="color:teal;"&gt;EventArgs&lt;/span&gt; e)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        closeSession();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;    #endregion&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now I'll make one generic DAO class with the help of previos PerRequestWebManager.&lt;/p&gt;&lt;p&gt;&lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof1251\uc1 \deff0{\fonttbl{\f0\fnil\fcharset204\fprq1 Courier New;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0??;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;??\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;??\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;??\red192\green192\blue192;}??\fs20 \cf2 public\cf0  \cf2 class\cf0  \cf10 GenericDAO\cf0 &lt;t&gt;\par ??\{\par ??    \cf2 public\cf0  GenericDAO()\par ??    \{\par ??        orm = \cf10 OrmManagerFactory\cf0 .GetInstance();\par ??    \}\par ??\par ??    \cf2 private\cf0  \cf10 OrmManager\cf0  orm;\par ??\par ??    \cf2 public\cf0  T Load(\cf2 object\cf0  id)\par ??    \{\par ??        \cf2 return\cf0  (T) orm.session.Load(\cf2 typeof\cf0 (T), id);\par ??    \}\par ??    \par ??    \cf2 public\cf0  \cf2 void\cf0  Save(T entity)\par ??    \{\par ??        \cf2 bool\cf0  manageTransaction = ! orm.isActiveTransaction;\par ??        \cf2 if\cf0  (manageTransaction)\par ??        \{\par ??            orm.BeginTransaction(\cf10 IsolationLevel\cf0 .ReadCommitted);\par ??        \}\par ??        \cf2 try\par ??\cf0         \{\par ??            orm.session.SaveOrUpdate(entity);\par ??\par ??            \cf2 if\cf0  (manageTransaction)\par ??            \{\par ??                orm.CommitTransaction();\par ??            \}\par ??        \}\cf2 catch\cf0 (\cf10 Exception\cf0  e)\par ??        \{\par ??            \cf2 if\cf0  (manageTransaction)\par ??            \{\par ??                orm.RollbackTransaction();\par ??            \}\par ??            \par ??            \cf2 throw\cf0  e;\par ??        \}            \par ??    \}\par ??\}\par ??} --&gt;&lt;br /&gt;&lt;div style="BACKGROUND: white;font-family:Courier New;font-size:10pt;color:black;"   &gt;&lt;pre style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:teal;"&gt;GenericDAO&lt;/span&gt;&amp;lt;T&amp;gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;{&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; GenericDAO()&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        orm = &lt;span style="color:teal;"&gt;OrmManagerFactory&lt;/span&gt;.GetInstance();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:teal;"&gt;OrmManager&lt;/span&gt; orm;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; T Load(&lt;span style="color:blue;"&gt;object&lt;/span&gt; id)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;return&lt;/span&gt; (T) orm.session.Load(&lt;span style="color:blue;"&gt;typeof&lt;/span&gt;(T), id);&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; Save(T entity)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;bool&lt;/span&gt; manageTransaction = ! orm.isActiveTransaction;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;if&lt;/span&gt; (manageTransaction)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            orm.BeginTransaction(&lt;span style="color:teal;"&gt;IsolationLevel&lt;/span&gt;.ReadCommitted);&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;try&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            orm.session.SaveOrUpdate(entity);&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;if&lt;/span&gt; (manageTransaction)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                orm.CommitTransaction();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        }&lt;span style="color:blue;"&gt;catch&lt;/span&gt;(&lt;span style="color:teal;"&gt;Exception&lt;/span&gt; e)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;if&lt;/span&gt; (manageTransaction)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;                orm.RollbackTransaction();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;throw&lt;/span&gt; e;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        }            &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="BACKGROUND: white;font-family:Courier New;font-size:10pt;color:black;"   &gt;&lt;pre style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:teal;"&gt;OrmManagerFactory&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;{&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;private&lt;/span&gt; OrmManagerFactory()&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;const&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; ORM_MANAGER_TYPE_SECTION = &lt;span style="color:maroon;"&gt;"OrmManager"&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:teal;"&gt;OrmManager&lt;/span&gt; GetInstance()&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;string&lt;/span&gt; ormType = &lt;span style="color:teal;"&gt;ConfigurationManager&lt;/span&gt;.AppSettings[ORM_MANAGER_TYPE_SECTION];&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;if&lt;/span&gt; (ormType == &lt;span style="color:blue;"&gt;typeof&lt;/span&gt;(&lt;span style="color:teal;"&gt;PerRequestWebManager&lt;/span&gt;).Name)&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:teal;"&gt;PerRequestWebManager&lt;/span&gt;();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;else&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        {&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;throw&lt;/span&gt; &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:teal;"&gt;Exception&lt;/span&gt;(&lt;span style="color:maroon;"&gt;"Unknown ORM manager type"&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And here's how all of the above can be used in ASP.NET application:&lt;/p&gt;&lt;p&gt;&lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof1251\uc1 \deff0{\fonttbl{\f0\fnil\fcharset204\fprq1 Courier New;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0??;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;??\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;??\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;??\red192\green192\blue192;}??\fs20 \cf10 GenericDAO\cf0 &lt;\cf10 Article\cf0&gt; articleDao = \cf2 new\cf0  \cf10 GenericDAO\cf0 &lt;\cf10 Article\cf0&gt;();\par ??\par ??\cf10 Article\cf0  article = articleDao.Load(1);\par ??article.Name = \cf13 "Paracetamol"\cf0 ;\par ??article.SalePrice = rnd.NextDouble();\par ??articleDao.Save(article);\par ??} --&gt;&lt;br /&gt;&lt;div style="BACKGROUND: white;font-family:Courier New;font-size:10pt;color:black;"   &gt;&lt;pre style="MARGIN: 0px"&gt;&lt;span style="color:teal;"&gt;GenericDAO&lt;/span&gt;&amp;lt;&lt;span style="color:teal;"&gt;Article&lt;/span&gt;&amp;gt; articleDao = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:teal;"&gt;GenericDAO&lt;/span&gt;&amp;lt;&lt;span style="color:teal;"&gt;Article&lt;/span&gt;&amp;gt;();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;&lt;span style="color:teal;"&gt;Article&lt;/span&gt; article = articleDao.Load(1);&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;article.Name = &lt;span style="color:maroon;"&gt;"Paracetamol"&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;article.SalePrice = rnd.NextDouble();&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;articleDao.Save(article);&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you are interested I can mail you full source of this post. Enjoy!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31061699-115385127998541264?l=szahariev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://szahariev.blogspot.com/feeds/115385127998541264/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=31061699&amp;postID=115385127998541264" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115385127998541264?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/31061699/posts/default/115385127998541264?v=2" /><link rel="alternate" type="text/html" href="http://szahariev.blogspot.com/2006/07/nhibernate-session-management.html" title="NHibernate Session Management" /><author><name>Stephan Zahariev</name><uri>http://www.blogger.com/profile/11128408750332856474</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>4</thr:total></entry></feed>

