<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-8757739037105656062</atom:id><lastBuildDate>Thu, 17 Sep 2015 05:01:05 +0000</lastBuildDate><category>NHibernate</category><category>uNHAddins</category><category>Conversation</category><category>Session</category><category>Windows Forms</category><category>CallingConvention</category><category>Configuration</category><category>Criteria</category><category>Custom Validator</category><category>DLL</category><category>Debugger</category><category>DllImport</category><category>Encryption</category><category>Events</category><category>ICriterion</category><category>IUserType</category><category>KnownType</category><category>Lambda</category><category>Legacy</category><category>Multiple Session Factory</category><category>NHibernate Validator</category><category>NUnitEx</category><category>NullObject</category><category>Tests</category><category>Transformer</category><category>Unit Test</category><category>Validation</category><category>Visual Studio</category><category>WCF</category><category>natural-id</category><category>svn</category><title>Gustavo Ringel</title><description></description><link>http://gustavoringel.blogspot.com/</link><managingEditor>noreply@blogger.com (Gustavo Ringel)</managingEditor><generator>Blogger</generator><openSearch:totalResults>23</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-2204435769515233549</guid><pubDate>Fri, 12 Jul 2013 11:57:00 +0000</pubDate><atom:updated>2013-07-12T14:57:37.055+03:00</atom:updated><title>Moving the blog</title><description>I&#39;m in the process of moving this blog to &lt;a href=&quot;http://blog.gustavoringel.com/&quot;&gt;&lt;/a&gt; and to start blogging again after some busy time... It will take me a few days more to complete moving everything and start publishing there...but i&#39;ll remove this blog when I complete the work...</description><link>http://gustavoringel.blogspot.com/2013/07/moving-blog.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-3155899748756223092</guid><pubDate>Tue, 15 Jun 2010 13:37:00 +0000</pubDate><atom:updated>2010-06-16T11:52:48.894+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Debugger</category><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><title>Problem debugging with multiple processes</title><description>&lt;p&gt;For some reasons when debugging applications using multiple threads i had an awkward behavior with Visual Studio 2008 SP1, where the debugger will skip some steps or act as I pressed F5.&lt;/p&gt;  &lt;p&gt;After looking for a while in the web I arrived to a hotfix that solves this problem and it applies only for VS 2008 SP1.&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://support.microsoft.com/?scid=kb;en-us;957912&amp;amp;x=9&amp;amp;y=14&quot;&gt;http://support.microsoft.com/?scid=kb;en-us;957912&amp;amp;x=9&amp;amp;y=14&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I hope this is useful for other people suffering the same issues.&lt;/p&gt;</description><link>http://gustavoringel.blogspot.com/2010/06/problem-debugging-with-multiple.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-4219411556752737838</guid><pubDate>Sat, 13 Feb 2010 12:15:00 +0000</pubDate><atom:updated>2010-02-13T14:16:23.408+02:00</atom:updated><title>Is NHibernate difficult or why people do not read documentation</title><description>&lt;p&gt;I found this post in google alert today&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://mattthr.blogspot.com/2010/02/quey-across-join-in-nhibernate.html&quot;&gt;http://mattthr.blogspot.com/2010/02/quey-across-join-in-nhibernate.html&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;He claims this SQL is easy to write and he says that he has to work a lot with the highly “undocumented?” stupid framework called NH to make it work&lt;/p&gt;  &lt;p&gt;SELECT * from product p   &lt;br /&gt;inner join sku s on s.id = p.id    &lt;br /&gt;WHERE p.Name like &#39;%widget%&#39;    &lt;br /&gt;OR s.SkuCode like &#39;%wd_%&#39;&lt;/p&gt;  &lt;p&gt;If i write it as i write every query like this, the corresponding HQL will be something like:&lt;/p&gt;  &lt;p&gt;SELECT p from product p    &lt;br /&gt; join p.SKU s    &lt;br /&gt;WHERE p.Name like &#39;%widget%&#39;    &lt;br /&gt;OR s.SkuCode like &#39;%wd_%&#39;&lt;/p&gt;  &lt;p&gt;I mean is it easier in NH or what? And this feature is much documented…there is a trend of users trying to use criteria as the default…which i don’t think is right at all…criteria has its place and it will be overridden by a good implementation of Linq2NH but if all what you want is some translation of your SQL world to NH then you should use HQL.&lt;/p&gt;  </description><link>http://gustavoringel.blogspot.com/2010/02/is-nhibernate-difficult-or-why-people.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>6</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-947928247408742814</guid><pubDate>Fri, 20 Nov 2009 09:22:00 +0000</pubDate><atom:updated>2009-11-20T11:23:13.214+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Criteria</category><category domain="http://www.blogger.com/atom/ns#">ICriterion</category><category domain="http://www.blogger.com/atom/ns#">NHibernate</category><category domain="http://www.blogger.com/atom/ns#">uNHAddins</category><title>Extending ICriterion to use a sql LIKE for a numeric field</title><description>&lt;p&gt;I’m almost sure it is not ANSI-SQL but, in SQL Server you can do a Like query for an int field.&lt;/p&gt;  &lt;p&gt;Using the Like Restriction in NHibernate won’t send a like for an int field, because it is not supported for every DB. I’m migrating an application which uses like for integer fields to find domain objects which some codes starts with a known prefix.&lt;/p&gt;  &lt;p&gt;Considering that I’m working now with SQL Server and i don’t think about migrating the app to another database i decided to extend ICriterion to get this using a StartsWith restriction&lt;/p&gt;  &lt;p&gt;The work is very easy, basically when i create the expression i convert it in a LikeExpression, and convert the value toString, in SQL if you send a string to a like for a numeric value it will return an empty result set which for me is good enough:&lt;/p&gt;  &lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color: blue&quot;&gt;public class &lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;StartsWithExpression &lt;/span&gt;: &lt;span style=&quot;color: #2b91af&quot;&gt;AbstractCriterion&lt;br /&gt;    &lt;/span&gt;{&lt;br /&gt;        &lt;span style=&quot;color: blue&quot;&gt;private readonly &lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;ICriterion &lt;/span&gt;realCriterion;&lt;br /&gt;        &lt;br /&gt;        &lt;span style=&quot;color: gray&quot;&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;        /// &lt;/span&gt;&lt;span style=&quot;color: green&quot;&gt;Initialize a new instance of the &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;&amp;lt;see cref=&amp;quot;EqOrNullExpression&amp;quot; /&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: green&quot;&gt;class for a named&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;/// &lt;/span&gt;&lt;span style=&quot;color: green&quot;&gt;Property and its value.&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;        /// &amp;lt;param name=&amp;quot;propertyName&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: green&quot;&gt;The name of the Property in the class.&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;        /// &amp;lt;param name=&amp;quot;value&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: green&quot;&gt;The value for the Property.&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;public &lt;/span&gt;StartsWithExpression(&lt;span style=&quot;color: blue&quot;&gt;string &lt;/span&gt;propertyName, &lt;span style=&quot;color: blue&quot;&gt;object &lt;/span&gt;value)&lt;br /&gt;        {&lt;br /&gt;            realCriterion= &lt;span style=&quot;color: blue&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;LikeExpression&lt;/span&gt;(propertyName, value.ToString(), &lt;span style=&quot;color: #2b91af&quot;&gt;MatchMode&lt;/span&gt;.Start);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue&quot;&gt;public override string &lt;/span&gt;ToString()&lt;br /&gt;        {&lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;realCriterion.ToString();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue&quot;&gt;public override &lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;TypedValue&lt;/span&gt;[] GetTypedValues(&lt;span style=&quot;color: #2b91af&quot;&gt;ICriteria &lt;/span&gt;criteria, &lt;span style=&quot;color: #2b91af&quot;&gt;ICriteriaQuery &lt;/span&gt;criteriaQuery)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;realCriterion.GetTypedValues(criteria, criteriaQuery);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue&quot;&gt;public override &lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;IProjection&lt;/span&gt;[] GetProjections()&lt;br /&gt;        {&lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;realCriterion.GetProjections();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue&quot;&gt;public override &lt;/span&gt;&lt;span style=&quot;color: #2b91af&quot;&gt;SqlString &lt;/span&gt;ToSqlString(&lt;span style=&quot;color: #2b91af&quot;&gt;ICriteria &lt;/span&gt;criteria, &lt;span style=&quot;color: #2b91af&quot;&gt;ICriteriaQuery &lt;/span&gt;criteriaQuery,&lt;br /&gt;                                              &lt;span style=&quot;color: #2b91af&quot;&gt;IDictionary&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: #2b91af&quot;&gt;IFilter&lt;/span&gt;&amp;gt; enabledFilters)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style=&quot;color: blue&quot;&gt;return &lt;/span&gt;realCriterion.ToSqlString(criteria, criteriaQuery, enabledFilters);&lt;br /&gt;        }&lt;br /&gt;    }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The code is ready in the &lt;a href=&quot;http://code.google.com/p/unhaddins/&quot; target=&quot;_blank&quot;&gt;uNhAddins source&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Next thing i want to do is use this in an Example query and get the EnableLike to work with it, but currently i didn’t find out how to extend Example for this.&lt;/p&gt;  </description><link>http://gustavoringel.blogspot.com/2009/11/extending-icriterion-to-make-like-for.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-1873997219025859929</guid><pubDate>Thu, 19 Nov 2009 12:43:00 +0000</pubDate><atom:updated>2009-11-19T14:45:37.971+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Conversation</category><category domain="http://www.blogger.com/atom/ns#">Multiple Session Factory</category><category domain="http://www.blogger.com/atom/ns#">uNHAddins</category><title>uNHAddins MultiSessionFactory and Conversation</title><description>&lt;p&gt;I have been asked sometimes in the Blog comments, without time to answer, how to configure the conversation to use a MultiSessionFactoryProvider instead of the regular SessionFactoryProvider we use in most of the examples.&lt;/p&gt;  &lt;p&gt;The real place to start this is &lt;a href=&quot;http://fabiomaulo.blogspot.com/2009/09/configure-sessionfactory-providers.html&quot; target=&quot;_blank&quot;&gt;Fabio’s Blog&lt;/a&gt; where he talks about the SessionFactory providers.&lt;/p&gt;  &lt;p&gt;I took the ideas from there, configured the conversation and made a simple test that has a CrudModel for an animal and a person and shows them in a ConsoleApplication.&lt;/p&gt;  &lt;p&gt;You can find the example in the &lt;a href=&quot;http://code.google.com/p/unhaddins/source/browse/#svn/trunk/uNhAddIns/uNhAddIns.Example.MultiSessionConversationUsage&quot; target=&quot;_blank&quot;&gt;uNHAddins source&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;For sure it is not the best example you will see, but you can see how easily you can configure your repositories / daos to access one factory or other using uNHAddins&lt;/p&gt;  </description><link>http://gustavoringel.blogspot.com/2009/11/unhaddins-multisessionfactory-and.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-7172409504466264374</guid><pubDate>Tue, 07 Jul 2009 06:12:00 +0000</pubDate><atom:updated>2009-07-07T21:54:03.370+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Events</category><category domain="http://www.blogger.com/atom/ns#">Lambda</category><category domain="http://www.blogger.com/atom/ns#">NUnitEx</category><category domain="http://www.blogger.com/atom/ns#">Unit Test</category><title>Asserting an event was raised</title><description>&lt;p&gt;I found the answer to this in some posts in the net. But i always forgot it and find my self looking for it again, so i will post the solution Im using here for future reference.&lt;/p&gt;  &lt;pre class=&quot;code&quot;&gt;[&lt;span style=&quot;color:#2b91af;&quot;&gt;Test&lt;/span&gt;]&lt;br /&gt;&lt;span style=&quot;color:blue;&quot;&gt;public void &lt;/span&gt;during_single_load_getting_two_barcode_raises_event_with_them()&lt;br /&gt;{&lt;br /&gt;&lt;span style=&quot;color:blue;&quot;&gt;  var &lt;/span&gt;eventRaised = &lt;span style=&quot;color:blue;&quot;&gt;false&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;dispenserProcessManager = CreateStubbedDispenserManager();&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;var &lt;/span&gt;barcodes = &lt;span style=&quot;color:blue;&quot;&gt;new&lt;/span&gt;[] { &lt;span style=&quot;color:#a31515;&quot;&gt;&quot;4444455555&quot;&lt;/span&gt;, &lt;span style=&quot;color:#a31515;&quot;&gt;&quot;4444455556&quot; &lt;/span&gt;};&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;  busterManager.Stub(bm =&amp;gt; bm.GetSingleLoadBarcodes(&lt;span style=&quot;color:#2b91af;&quot;&gt;Context&lt;/span&gt;.TelephoneType)).Return(barcodes);&lt;br /&gt;&lt;br /&gt;dispenserProcessManager.BarcodesRead += (sender, collection) =&amp;gt;&lt;br /&gt;{&lt;br /&gt;collection.Elements.Count().Should().Be.EqualTo(2);&lt;br /&gt;collection.Elements.Should().Contain(barcodes[0]);&lt;br /&gt;collection.Elements.Should().Contain(barcodes[1]);&lt;br /&gt;eventRaised = &lt;span style=&quot;color:blue;&quot;&gt;true&lt;/span&gt;;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;dispenserProcessManager.SingleLoad();&lt;br /&gt;&lt;br /&gt;eventRaised.Should().Be.True();&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;Inside the event i’m checking that the event was raised with the right data, and i set the eventraised variable to true. At the end i check that i really hit that line.&lt;/p&gt;&lt;p&gt;The Should() syntax is a handy way of asserting (at least for me) using &lt;a href=&quot;http://code.google.com/p/nunitex/&quot; target=&quot;_blank&quot;&gt;NunitEx&lt;/a&gt;&lt;/p&gt;</description><link>http://gustavoringel.blogspot.com/2009/07/asserting-event-was-raised-in-rhino.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-7903354946300747601</guid><pubDate>Fri, 29 May 2009 20:26:00 +0000</pubDate><atom:updated>2009-05-30T00:00:32.702+03:00</atom:updated><title>Rhino Mocks Constraints for Generic List</title><description>&lt;p&gt;Today i was doing some tests that check that user input in a windows forms is ok and sends a notification to the user.&lt;/p&gt;  &lt;p&gt;The notification is a list of Errors, each error has the control which has a problem and the message to show to the user, all of this to set the ErrorProvider.&lt;/p&gt;  &lt;p&gt;Well i really want to test I’m sending the right things, but i don’t care if the error provider works fine, so i obviously decided to mock the view…&lt;/p&gt;  &lt;p&gt;I’m not so acquainted with Rhino Mocks but find very nice the way to set the expectation for the list of errors that should be passed to the view.&lt;/p&gt;  &lt;pre class=&quot;code&quot;&gt;view.Expect(v =&amp;gt; v.NotifyErrors(&lt;span style=&quot;color:blue;&quot;&gt;null&lt;/span&gt;).Constraints(&lt;br /&gt;               &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;List&lt;/span&gt;.Count(&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;Is&lt;/span&gt;.Equal(1)) &amp;amp;&amp;amp;&lt;br /&gt;               &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;Is&lt;/span&gt;.TypeOf&amp;lt;&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;Error&lt;/span&gt;&amp;gt;&amp;gt;() &amp;amp;&amp;amp;&lt;br /&gt;               &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;List&lt;/span&gt;.Element(0, &lt;span style=&quot;color:blue;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;PropertyIs&lt;/span&gt;(&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;&quot;Message&quot;&lt;/span&gt;, &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;Messages&lt;/span&gt;.ToDateCannotBeLessThanFromDate)));&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;The only thing i would like to improve is the string in the PropertyIs, i maybe missing some option to do e =&amp;gt; e.Message == &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;Messages&lt;/span&gt;.ToDateCannotBeLessThanFromDate&lt;/pre&gt;</description><link>http://gustavoringel.blogspot.com/2009/05/rhino-mocks-constraints-for-generic.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-8758228962492908017</guid><pubDate>Fri, 22 May 2009 20:13:00 +0000</pubDate><atom:updated>2009-05-22T23:15:31.490+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">KnownType</category><category domain="http://www.blogger.com/atom/ns#">NullObject</category><category domain="http://www.blogger.com/atom/ns#">WCF</category><title>Using KnownType for NullObject</title><description>&lt;p&gt;I’m a little fan of &lt;a href=&quot;http://en.wikipedia.org/wiki/Null_Object_pattern&quot; target=&quot;_blank&quot;&gt;NullObject&lt;/a&gt; pattern. It is very handy for several use cases.&lt;/p&gt;  &lt;p&gt;I was moving my application to WCF and defined my User as a [DataContract] and my NullUser as a [DataContract]. The login service will return a User if it exists or a NullUser if it doesn’t exist.&lt;/p&gt;  &lt;p&gt;Well I was naively thinking it will work as is…but instead of that i got an exception it could not Serialize because NullUser was not expected as a contract…&lt;/p&gt;  &lt;p&gt;The solution is very easy, putting the KnownType(typeof(NullUser)) as an attribute on top of the User class…then i can keep playing with my null objects.&lt;/p&gt;</description><link>http://gustavoringel.blogspot.com/2009/05/using-knowntype-for-nullobject.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-212093392529730198</guid><pubDate>Sun, 26 Apr 2009 10:19:00 +0000</pubDate><atom:updated>2009-04-26T13:21:26.990+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">natural-id</category><category domain="http://www.blogger.com/atom/ns#">NHibernate</category><title>Using the &lt;natural-id&gt; tag in NHibernate</title><description>&lt;p&gt;In NHibernate we usually use a surrogate key to represent an Id for our class. However our entities always have some natural business key like Order + OrderLine.&lt;/p&gt;  &lt;p&gt;The problem is that there was no way to create this unique constraint for composed natural keys without using &amp;lt;database-object&amp;gt; which is not the best solution.&lt;/p&gt;  &lt;p&gt;Since the introduction of Alpha1 we have a solution for this using the tag &amp;lt;natural-id&amp;gt; you put every property composing the Natural key inside the mapping and NH will generate the necessary unique key and nullability constraints&lt;/p&gt;  &lt;p&gt;So if you have this mapping&lt;/p&gt;  &lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color:blue;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;class &lt;/span&gt;&lt;span style=&quot;color:red;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;Warehouse&lt;/span&gt;&quot; &lt;span style=&quot;color:red;&quot;&gt;table&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;Warehouses&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;&amp;gt;&lt;br /&gt;   &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;id &lt;/span&gt;&lt;span style=&quot;color:red;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;Id&lt;/span&gt;&quot; &lt;span style=&quot;color:red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;Int32&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;&amp;gt;&lt;br /&gt;       &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;generator &lt;/span&gt;&lt;span style=&quot;color:red;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;hilo&lt;/span&gt;&quot; &lt;span style=&quot;color:blue;&quot;&gt;/&amp;gt;&lt;br /&gt;   &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;&amp;gt;&lt;br /&gt;&lt;br /&gt;   &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;many-to-one &lt;/span&gt;&lt;span style=&quot;color:red;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;ServiceCenter&lt;/span&gt;&quot; &lt;span style=&quot;color:red;&quot;&gt;column&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;ServiceCenterId&lt;/span&gt;&quot; &lt;span style=&quot;color:blue;&quot;&gt;/&amp;gt;&lt;br /&gt;   &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;property &lt;/span&gt;&lt;span style=&quot;color:red;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;Code&lt;/span&gt;&quot; &lt;span style=&quot;color:red;&quot;&gt;not-null&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;true&lt;/span&gt;&quot; &lt;span style=&quot;color:red;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;16&lt;/span&gt;&quot; &lt;span style=&quot;color:blue;&quot;&gt;/&amp;gt;&lt;br /&gt;&lt;br /&gt;   &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;property &lt;/span&gt;&lt;span style=&quot;color:red;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;Description&lt;/span&gt;&quot; &lt;span style=&quot;color:red;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;128&lt;/span&gt;&quot; &lt;span style=&quot;color:blue;&quot;&gt;/&amp;gt;&lt;br /&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;NH will generate:&lt;br /&gt;&lt;p&gt;CREATE TABLE StockManagement.dbo.Warehouses (&lt;br /&gt;        Id INT not null,&lt;br /&gt;       ServiceCenterId INT null,&lt;br /&gt;       Code NVARCHAR(16) not null,&lt;br /&gt;       Description NVARCHAR(128) null,&lt;br /&gt;       primary key (Id)&lt;br /&gt;    )&lt;/p&gt;and if now you add it the &amp;lt;natural-id&amp;gt; tag&lt;br /&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span style=&quot;color:blue;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;class &lt;/span&gt;&lt;span style=&quot;color:red;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;Warehouse&lt;/span&gt;&quot; &lt;span style=&quot;color:red;&quot;&gt;table&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;Warehouses&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;&amp;gt;&lt;br /&gt;   &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;id &lt;/span&gt;&lt;span style=&quot;color:red;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;Id&lt;/span&gt;&quot; &lt;span style=&quot;color:red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;Int32&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;&amp;gt;&lt;br /&gt;       &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;generator &lt;/span&gt;&lt;span style=&quot;color:red;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;hilo&lt;/span&gt;&quot; &lt;span style=&quot;color:blue;&quot;&gt;/&amp;gt;&lt;br /&gt;   &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;&amp;gt;&lt;br /&gt;&lt;br /&gt;   &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;natural-id&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;&amp;gt;&lt;br /&gt;       &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;many-to-one &lt;/span&gt;&lt;span style=&quot;color:red;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;ServiceCenter&lt;/span&gt;&quot; &lt;span style=&quot;color:red;&quot;&gt;column&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;ServiceCenterId&lt;/span&gt;&quot; &lt;span style=&quot;color:blue;&quot;&gt;/&amp;gt;&lt;br /&gt;       &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;property &lt;/span&gt;&lt;span style=&quot;color:red;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;Code&lt;/span&gt;&quot; &lt;span style=&quot;color:red;&quot;&gt;not-null&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;true&lt;/span&gt;&quot; &lt;span style=&quot;color:red;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;16&lt;/span&gt;&quot; &lt;span style=&quot;color:blue;&quot;&gt;/&amp;gt;&lt;br /&gt;   &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;natural-id&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;&amp;gt;&lt;br /&gt;&lt;br /&gt;   &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;property &lt;/span&gt;&lt;span style=&quot;color:red;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;Description&lt;/span&gt;&quot; &lt;span style=&quot;color:red;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color:blue;&quot;&gt;128&lt;/span&gt;&quot; &lt;span style=&quot;color:blue;&quot;&gt;/&amp;gt;&lt;br /&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;you will get the DDL (i underline the addition):&lt;br /&gt;&lt;p&gt;CREATE TABLE StockManagement.dbo.Warehouses (&lt;br /&gt;        Id INT not null,&lt;br /&gt;       ServiceCenterId INT null,&lt;br /&gt;       Code NVARCHAR(16) not null,&lt;br /&gt;       Description NVARCHAR(128) null,&lt;br /&gt;       primary key (Id),&lt;br /&gt;      &lt;u&gt;unique (ServiceCenterId, Code)&lt;/u&gt;&lt;br /&gt;    )&lt;/p&gt;&lt;p&gt;This way your mapping can be more self documenting. For sure it will help also for tests instead of adding manually these constraints.&lt;/p&gt;</description><link>http://gustavoringel.blogspot.com/2009/04/using-tag-in-nhibernate.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>5</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-5268264978280915046</guid><pubDate>Sat, 25 Apr 2009 19:59:00 +0000</pubDate><atom:updated>2009-04-25T23:02:15.338+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Custom Validator</category><category domain="http://www.blogger.com/atom/ns#">NHibernate</category><category domain="http://www.blogger.com/atom/ns#">NHibernate Validator</category><category domain="http://www.blogger.com/atom/ns#">Validation</category><title>Using the NHibernate Validator with a Custom Attribute</title><description>&lt;p&gt;The NHibernate Validator has an XML Configuration that covers every standard validator attribute that can be defined.&lt;/p&gt;  &lt;p&gt;It is nice because you can change validations without changing code, etc, etc.&lt;/p&gt;  &lt;p&gt;One question that arises several times is how to use XML when defining a new Attribute + Validator like those in the Country Specifics Validators. &lt;/p&gt;  &lt;p&gt;The &amp;lt;rule&amp;gt; tag takes care of this. If you define a custom attribute then you give the full class name of the attribute and the parameters in the xml file like this.&lt;/p&gt;  &lt;pre&gt;&lt;pre   style=&quot;margin: 0em; background-color: rgb(255, 255, 255); width: 100%;font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;rule&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;attribute&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;AttributeFullClassName&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; background-color: rgb(255, 255, 255); width: 100%;font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&lt;span style=&quot;color:#333333;&quot;&gt;  &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;param&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;name&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;Value1&quot;&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;value&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;A string value&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; background-color: rgb(255, 255, 255); width: 100%;font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;  &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;param&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;name&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;Value2&quot;&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;value&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;123&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; background-color: rgb(255, 255, 255); width: 100%;font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;  &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;param&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;name&lt;/span&gt; =&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;Message&quot;&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;value&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;custom message&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; background-color: rgb(255, 255, 255); width: 100%;font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;rule&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;So you can keep using XML even for your custom validators.</description><link>http://gustavoringel.blogspot.com/2009/04/using-nhibernate-validator-with-custom.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-6304597401870420485</guid><pubDate>Mon, 20 Apr 2009 20:40:00 +0000</pubDate><atom:updated>2009-04-20T23:44:17.528+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Configuration</category><category domain="http://www.blogger.com/atom/ns#">NHibernate</category><title>format_sql property in NHibernate</title><description>&lt;p&gt;Talking with Fabio the last days I found out that the format_sql property which implementation was missing in NHibernate was added for NH Alpha3. The JIRA issue is the following:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://nhjira.koah.net/browse/NH-1745&quot;&gt;http://nhjira.koah.net/browse/NH-1745&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This means that instead of getting a loooooong line for  NHibernate.Tool.hbm2ddl.SchemaExport and NHibernate.SQL queries we are getting nicest things in the log like:&lt;/p&gt;  &lt;p&gt;INSERT &lt;br /&gt;    INTO   &lt;br /&gt;        StockManagement.dbo.Locations   &lt;br /&gt;        (Code, Id) &lt;br /&gt;    VALUES   &lt;br /&gt;        (@p0, @p1);   &lt;br /&gt;    @p0 = 1, @p1 = 32768&lt;/p&gt;  &lt;p&gt;instead of previous:&lt;/p&gt;  &lt;p&gt;INSERT INTO StockManagement.dbo.Locations (Code, Id) VALUES (@p0, @p1);@p0 = 1, @p1 = 32768&lt;/p&gt;  &lt;p&gt;For sure i could have take a bigger query, but i think this is enough to show the case.&lt;/p&gt;  &lt;p&gt;I think this is a very nice feature to have when looking for problems.&lt;/p&gt;</description><link>http://gustavoringel.blogspot.com/2009/04/formatsql-property-in-nhibernate.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-2746894228555830954</guid><pubDate>Sun, 05 Apr 2009 09:30:00 +0000</pubDate><atom:updated>2009-04-05T12:34:05.472+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">CallingConvention</category><category domain="http://www.blogger.com/atom/ns#">DLL</category><category domain="http://www.blogger.com/atom/ns#">DllImport</category><category domain="http://www.blogger.com/atom/ns#">Legacy</category><title>Using an external C++ DLL</title><description>&lt;p&gt;Today I had again to call a legacy DLL and again I was in trouble until I found the project where I worked on this in the past…so I decided to put me a reminder in the blog…hoping for it to be easier to find. We have a lot of dll’s for several machines written in Borland C++ and I don’t think they are going to be rewritten in something else for long. &lt;/p&gt;  &lt;p&gt;So let’s say i need to call a method GetStatus exported by machine.dll &lt;/p&gt;  &lt;p&gt;1) I put the dll in the path of my binaries, 2) I declare a class importing several methods like this one:&lt;/p&gt;  &lt;pre class=&quot;code&quot;&gt;[&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;DllImport&lt;/span&gt;(&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;&quot;machine.dll&quot;&lt;/span&gt;, EntryPoint = &lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;&quot;GetStatus&quot;&lt;/span&gt;, CallingConvention = &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;CallingConvention&lt;/span&gt;.StdCall)]   &lt;br /&gt;&lt;span style=&quot;color:blue;&quot;&gt;public static extern int &lt;/span&gt;GetStatus(&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;StringBuilder &lt;/span&gt;builder);&lt;/pre&gt;The calling convention is dependent on the way the dll is compiled and I found that for every dll in my company StdCall is OK.&lt;br /&gt;&lt;p&gt;Regarding the StringBuilder it is a way to get a char* in C++ without having to take care of the \0 and other beauties…&lt;/p&gt;&lt;p&gt;In my case this is it because there is some abstractions there in our library i only pass a char* with an expected format and get back an integer representing the status…most of the call work this way.&lt;/p&gt;&lt;p&gt;So it will be easy for me to find what i need here and i hope someone finds this useful also.&lt;/p&gt;</description><link>http://gustavoringel.blogspot.com/2009/04/using-external-c-dll.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-4638084044017935136</guid><pubDate>Sun, 22 Mar 2009 22:21:00 +0000</pubDate><atom:updated>2009-03-23T00:23:05.482+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Tests</category><category domain="http://www.blogger.com/atom/ns#">uNHAddins</category><title>uNHAddins TestUtils, Spying your log</title><description>&lt;p&gt;Not a long time ago Fabio started his &lt;a href=&quot;http://code.google.com/p/unhaddins/&quot; target=&quot;_blank&quot;&gt;uNHAddins&lt;/a&gt; TestUtils project…it is not finished yet, he left it a little to run for NUnitEx. But there are already some useful things there, part of it will change for sure after using it for a little while, but there are things that i think are highly stable and will be very useful.&lt;/p&gt;  &lt;p&gt;One of them is something i always see myself copying from project to project, a LogSpy…this is something i always put in my test.commons.dll, copying from the uNHAddins or NH implementations but now it is part of uNHAddins.TestUtils, which is handy because I’m already using it.&lt;/p&gt;  &lt;p&gt;In the uNHAddins &lt;a href=&quot;http://code.google.com/p/unhaddins/source/browse/#svn/trunk/Examples/uNHAddins.Examples.SessionManagement&quot; target=&quot;_blank&quot;&gt;SessionManagement&lt;/a&gt; Example I’m testing that I’m logging that conversation was ended after persisting the modification of an order. The idea there was testing that i can catch the event after the conversation ended, so i can publish some event, or do something…for the sake of the test i only logged and Spyed using uNHAddins syntax as shown.&lt;/p&gt;  &lt;pre class=&quot;code&quot;&gt;[&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;Test&lt;/span&gt;]&lt;br /&gt;&lt;span style=&quot;color:blue;&quot;&gt;public void &lt;/span&gt;persisting_an_order_should_log_message()&lt;br /&gt;{&lt;br /&gt;&lt;span style=&quot;color:blue;&quot;&gt;&lt;span style=&quot;color:#333333;&quot;&gt;  &lt;/span&gt;var &lt;/span&gt;purchaseOrder = &lt;span style=&quot;color:blue;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;PurchaseOrder&lt;br /&gt; &lt;/span&gt;{&lt;br /&gt;   Date = &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;DateTime&lt;/span&gt;.Now,&lt;br /&gt;   Number = &lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;&quot;N1&quot;&lt;br /&gt; &lt;/span&gt;};&lt;br /&gt;&lt;br /&gt; A&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;ssert&lt;/span&gt;.That(&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;Spying&lt;/span&gt;.Logger(&lt;span style=&quot;color:blue;&quot;&gt;typeof &lt;/span&gt;&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;MyConversationCreationInterceptor&lt;/span&gt;&amp;lt;&amp;gt;))&lt;br /&gt;   .Execute(() =&amp;gt; modifyOrderModel.Persist(purchaseOrder))&lt;br /&gt;   .MessageSequence,&lt;br /&gt;   &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;Is&lt;/span&gt;.EqualTo(&lt;span style=&quot;color:blue;&quot;&gt;new&lt;/span&gt;[] { &lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;&quot;My conversation ended&quot; &lt;/span&gt;}));&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;There are some uses a bit more complex in the uNHAddins test, but that is it…in a simple way we can spay the log.&lt;/p&gt;</description><link>http://gustavoringel.blogspot.com/2009/03/unhaddins-testutils-spying-your-log.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-1564795518150473708</guid><pubDate>Wed, 11 Mar 2009 20:02:00 +0000</pubDate><atom:updated>2009-03-12T08:29:01.174+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Conversation</category><category domain="http://www.blogger.com/atom/ns#">NHibernate</category><category domain="http://www.blogger.com/atom/ns#">uNHAddins</category><title>uNHAddins SessionWrapper and performance optimization</title><description>&lt;p&gt;Rub posted in Fabio’s blog and mine he was having some problems with performance using uNHAddins conversation.&lt;/p&gt;  &lt;p&gt;I’m using the conversation for a while and i know there is no issue using it, so we asked Rub to send a test showing what he was doing to test. His test was comparing a direct call to a Dao method with a call through the Model. The time difference was being of… seconds!&lt;/p&gt;  &lt;p&gt;The first thing i did to check what’s going on was calling again the model function after the first call…from 1 second and something we moved to…a few milliseconds…so, the problem was with something occurring in the startup.&lt;/p&gt;  &lt;p&gt;Debugging a little, i found the problem was in the SessionWrapper with a call to a castle function CreateInterfaceProxyWithTarget. It was taking almost a second to generate the proxy to a session the first time.&lt;/p&gt;  &lt;p&gt;For sure we should review what is happening there so we can find or ask for a solution, if possible, so Castle lovers can keep using the DynamicProxy2, but for the ones worried about the slow initialization there is a very simple solution! using the uNHAddins.LinfuAdapters.SessionWrapper instead of the uNHAddins.CastleAdapters.SessionWrapper, so the proxy is given by LinFu there…guess what…now the initialization is way faster, without changing code…&lt;/p&gt;  &lt;p&gt;So in resume, you can keep trusting on uNHAddins conversation and you’re still invited to create tests and send to the uNHaddins forum if you find something that is suspicious in the current implementation…a better follow up of this solution can be found in the forum also.&lt;/p&gt;</description><link>http://gustavoringel.blogspot.com/2009/03/unhaddins-sessionwrapper-and.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-1316253749288782759</guid><pubDate>Wed, 25 Feb 2009 21:55:00 +0000</pubDate><atom:updated>2009-02-27T15:10:38.013+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">NHibernate</category><category domain="http://www.blogger.com/atom/ns#">Transformer</category><category domain="http://www.blogger.com/atom/ns#">uNHAddins</category><title>Creating a DTO in NHibernate + HQL using PositionalToBeanResultTransformer</title><description>&lt;p&gt;The most common way to create a DTO in NHibernate (for me at least) is having a public constrctor…let’s say we have class product &lt;/p&gt;  &lt;pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;class&lt;/span&gt; Product&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;{&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public virtual string &lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;Id&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;{&lt;/span&gt; get&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;;&lt;/span&gt; set&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;;&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;virtual&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;string&lt;/span&gt; Code { &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;set&lt;/span&gt;; }&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;virtual&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;string&lt;/span&gt; Description { &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;set&lt;/span&gt;; }&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;virtual&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;double&lt;/span&gt; Price { &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;set&lt;/span&gt;; }&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;}&lt;/pre&gt;&lt;/pre&gt;&lt;p&gt;and we want to create a ProductDTO then for the classical solution we will need also a specific constructor in the ProductDTO&lt;/p&gt;&lt;pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;class&lt;/span&gt; ProductDTO&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;p&gt;{&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; ProductDTO(&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;int&lt;/span&gt; code, &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;string&lt;/span&gt; description)&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;{&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;  Code = code&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;  Description = description&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;}&lt;/pre&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;virtual&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;string&lt;/span&gt; Code { &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;set&lt;/span&gt;; }&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;virtual&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;double&lt;/span&gt; Description { &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;set&lt;/span&gt;; }&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;}&lt;/pre&gt;&lt;/pre&gt;&lt;pre&gt;in the mapping class you will need to add an import of the DTO class and the named HQL something like:&lt;/pre&gt;&lt;pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;class&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;NH.Domain.DTOs.ProductDTO, NH.Domain&quot;&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;... (class mapping)&lt;br /&gt;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;  &gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;query&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;name&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;GetProductDTOClassical&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot; size=&quot;12px&quot; face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot;&gt;  select new ProductDTO(product.Code, product.Description)&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;  from Product product&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;query&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;p&gt;Finally you write the query:&lt;/p&gt;&lt;pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;var productDTO = &lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;  session.GetNamedQuery(&quot;&lt;span style=&quot;color: rgb(139, 0, 0);&quot;&gt;GetProductDTOClassical&lt;/span&gt;&quot;)&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;  .UniqueResult&amp;lt;ProductDTO&amp;gt;();&lt;/pre&gt;&lt;/pre&gt;&lt;p&gt;Well this works well, a lot of people is using it…so, why may we want an alternative for this? Well in my case i don’t like so much to be forced to have the constructor + the import + the new ProductDTO…that’s a lot of info i have to give in the mapping simply to get a DTO…&lt;/p&gt;&lt;p&gt;Using the &lt;a href=&quot;http://code.google.com/p/unhaddins/&quot; target=&quot;_blank&quot;&gt;uNHAddins&lt;/a&gt; PositionalToBeanResultTransformer you can avoid the constructor and the import. What you still need is a query for sure. But instead of telling you are returning a new ProductDTO, you return the product.Code and product.Description…then you let the Transformer to do all the work for you.&lt;/p&gt;&lt;p&gt;So the definition of the Product DTO and the query are now:&lt;/p&gt;&lt;pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;class&lt;/span&gt; ProductDTO&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;{&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;  &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;virtual&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;string&lt;/span&gt; Code { &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;set&lt;/span&gt;; }&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;  &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;virtual&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;double&lt;/span&gt; Description { &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;set&lt;/span&gt;; }&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;}&lt;/pre&gt;&lt;/pre&gt;&lt;pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;query&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;name&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;GetProductDTOCPositional&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt;  &lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;  select product.Code, product.Description  &lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;  from Product product&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;query&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;p&gt;Now you only need to instantiate an instance of PositionalToBeanTransformer telling it the type of the DTO as you would do with every transformer, but aditionally you tell it the name of the DTO properties that you are going to fill (static reflection will help here to avoid the strings) and you are done.&lt;/p&gt;&lt;pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;var transformer = &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&lt;br /&gt;new&lt;/span&gt; PositionalToBeanResultTransformer(&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;typeof&lt;/span&gt; (ProductDTO), &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;new&lt;/span&gt;[] {&quot;&lt;span style=&quot;color: rgb(139, 0, 0);&quot;&gt;Code&lt;/span&gt;&quot;, &quot;&lt;span style=&quot;color: rgb(139, 0, 0);&quot;&gt;Description&lt;/span&gt;&quot;});&lt;br /&gt;&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;var productDTO = &lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;  session.GetNamedQuery(&quot;&lt;span style=&quot;color: rgb(139, 0, 0);&quot;&gt;GetProductDTOPositional&lt;/span&gt;&quot;)&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;  .SetResultTransformer(transformer)&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;  .UniqueResult&amp;lt;ProductDTO&amp;gt;();&lt;/pre&gt;&lt;/pre&gt;&lt;p&gt;well this is less code, so for sure is a good alternative i feel some people may be against having properties and prefer readonly + constructor…well for this you should continue using the classical solution…but for those of us not concerned on this…this is a nice solution…&lt;/p&gt;</description><link>http://gustavoringel.blogspot.com/2009/02/creating-dto-in-nhibernate-hql-using.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>10</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-5779225885837802914</guid><pubDate>Fri, 20 Feb 2009 21:34:00 +0000</pubDate><atom:updated>2009-02-20T23:38:53.921+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">IUserType</category><category domain="http://www.blogger.com/atom/ns#">NHibernate</category><category domain="http://www.blogger.com/atom/ns#">uNHAddins</category><title>ToUpper and Trim string IUserTypes</title><description>&lt;p&gt;There are a lot of usable feature in uNHAddins…there is some people that i know that are using them. I think that it is a pity if people doesn’t get acquainted of this and implement it their selves once and once again…so i’m trying to post as much as i can about them…&lt;/p&gt;  &lt;p&gt;In a &lt;a href=&quot;http://gustavoringel.blogspot.com/2009/02/encrypting-password-or-other-strings-in.html&quot; target=&quot;_blank&quot;&gt;previous post&lt;/a&gt; i introduced the EncryptedString IUserType and how to use it including some typedef variations.&lt;/p&gt;  &lt;p&gt;There are two more user types there that you can use in some applications, or you can get ideas from them for some special cases.&lt;/p&gt;  &lt;p&gt;One of them is called UpperString and what it does in short is converting the string to upper case…so if you need to send this to the application to avoid case sensitivity or whatever…you may use it, if it is not a domain concern (it is almost never a domain concern)&lt;/p&gt;  &lt;p&gt;The second IUserType is called TrimString…it solves a problem i found mostly working with legacy databases where you have a CHAR(N) field, and you get for example “100     “ instead of “100” from the database. So if you suffer from this, then this is the IUserType for you…&lt;/p&gt;  &lt;p&gt;We are thinking on adding some parameters to this to decide if doing Right Trim, Left Trim, trimming some special character not only spaces…but i’m not sure if it worth, even if it is very simple to do it…if someone needs this i can add it for sure…&lt;/p&gt;</description><link>http://gustavoringel.blogspot.com/2009/02/toupper-and-trim-string-iusertypes.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-939491906960246681</guid><pubDate>Fri, 20 Feb 2009 09:42:00 +0000</pubDate><atom:updated>2009-02-21T19:23:30.256+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Conversation</category><category domain="http://www.blogger.com/atom/ns#">NHibernate</category><category domain="http://www.blogger.com/atom/ns#">Session</category><category domain="http://www.blogger.com/atom/ns#">uNHAddins</category><title>uNHAddins conversation additions</title><description>&lt;p&gt;Well &lt;a href=&quot;http://www.fabiomaulo.blogspot.com/&quot; target=&quot;_blank&quot;&gt;Fabio&lt;/a&gt; and i discussed some ideas…as always i only started thinking about how to implement them and he already had a complete solution for the things being discussed.&lt;/p&gt;  &lt;p&gt;At least to feel I collaborate I will resume some of the things Fabio had been working on. &lt;/p&gt;  &lt;p&gt;I added the new features to my &lt;a href=&quot;http://unhaddins.googlecode.com/svn/trunk/Examples/uNHAddins.Examples.SessionManagement/&quot; target=&quot;_blank&quot;&gt;sample project&lt;/a&gt; which was previously described &lt;a href=&quot;http://gustavoringel.blogspot.com/2009/02/unhaddins-persistence-conversation-part_08.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt; so i could play a little with tests. I also did it only looking at the code and svn log to feel how descriptive it was by itself.&lt;/p&gt;  &lt;p&gt;Well, there are some things very new and some things that where missing an implementation...&lt;br /&gt;&lt;/p&gt;&lt;p&gt;First of all the &lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;MethodsIncludeMode&lt;/span&gt; property for the &lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;PersistenceConversational&lt;/span&gt; attribute is working, you can set it to &lt;span style=&quot;font-style: italic;&quot;&gt;Implicit &lt;/span&gt;or &lt;span style=&quot;font-style: italic;&quot;&gt;Explicit&lt;/span&gt;. &lt;span style=&quot;font-style: italic;&quot;&gt;Implicit &lt;/span&gt;will asume every public virtual method is part of a persistence conversation and will use the defaults if you don’t mark it as &lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;PersistenceConversation &lt;/span&gt;with your own properties.  &lt;span style=&quot;font-style: italic;&quot;&gt;Explicit &lt;/span&gt;will consider only methods marked by you as part of the conversation.&lt;/p&gt;  &lt;p&gt;Next we had a &lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;DefaultEndMode &lt;/span&gt;which was there but was not plugged in, now you can use it so every conversation will use as the default, if you want to do crazy things like set every method with &lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;EndMode&lt;/span&gt;.End, well, it is easy to do it even if not so right :)&lt;/p&gt;  &lt;p&gt;Last but not least we can now set a &lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;ConversationConfigurationInterceptor &lt;/span&gt;either explicitly or injecting it using meantime the CastleAdapter. This means for example I can subscribe to every event of the conversation and explicitly do something if needed without doing a lot of work like i did in &lt;a href=&quot;http://gustavoringel.blogspot.com/2009/02/changing-default-conversation-factory.html&quot;&gt;this post&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;  &lt;p&gt;The way to set an explicit Interceptor is having a class that inherits from &lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;IConversationCreationInterceptor &lt;/span&gt;which will have to implement the Configure method which receives a conversation, there you attach your events to the conversation and it is done. In the [&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;PersistenceConversational&lt;/span&gt;] attribute you just set &lt;span style=&quot;color: rgb(0, 0, 0); font-style: italic;&quot;&gt;ConversationCreationInterceptor &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;= typeof(MyInterceptor)&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;The DI way is creating a generic interceptor class that inherits from &lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;IConversationCreationInterceptorConvention&lt;/span&gt;&amp;lt;T&amp;gt; where T : class, the implementation is the same and it can be associated to a model implementing a generic class which receives a model and implements the interface. This will work if the property &lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;UseConversationCreationInterceptorConvention of PersistenceConversational is &lt;/span&gt;set to true (which is the default).&lt;br /&gt;&lt;/p&gt;  &lt;p&gt;Well you can look at the code to see it working.&lt;/p&gt;</description><link>http://gustavoringel.blogspot.com/2009/02/unhaddins-conversation-additions.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-3145878081294059893</guid><pubDate>Thu, 19 Feb 2009 07:21:00 +0000</pubDate><atom:updated>2009-02-19T09:23:51.320+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Encryption</category><category domain="http://www.blogger.com/atom/ns#">NHibernate</category><category domain="http://www.blogger.com/atom/ns#">uNHAddins</category><title>Encrypting password (or other strings) in NHibernate</title><description>&lt;p&gt;As you can read in every forum the solution to encrypting/decrypting a password is using an IUserType. Implementing an IUserType in NH is somewhat easy, so we added to uNHAddins a user type which will do the encryption.&lt;/p&gt;  &lt;p&gt;The source code can be grabbed from &lt;a href=&quot;http://code.google.com/p/unhaddins/&quot; target=&quot;_blank&quot;&gt;uNHAddins&lt;/a&gt; &lt;a href=&quot;http://unhaddins.googlecode.com/svn/trunk/&quot; target=&quot;_blank&quot;&gt;trunk&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;If you use it “as is” you will get an encryption using the symmetric algorithm DESCryptoServiceProvider. There is no special decision for this but to have some default option to do the job.&lt;/p&gt;  &lt;p&gt;There are several ways to use the user type, the most common but less recommended (unless you are using it only once):&lt;/p&gt;  &lt;pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;property&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;name&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;Password&quot;&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;type&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;uNHAddIns.UserTypes.EncryptedString, uNHAddins&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;The preferred way will be using &amp;lt;typedef&amp;gt; to define the user type as in the following:&lt;br /&gt;&lt;pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;typedef&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;class&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;uNHAddIns.UserTypes.EncryptedString, uNHAddIns&quot;&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;name&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;Encrypted&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;  &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;param&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;name&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;encryptor&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt;uNhAddIns.UserTypes.uNHAddinsEncryptor, uNhAddIns&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;  &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;param&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;name&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;encryptionKey&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt;myRGBKey&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;typedef&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;p&gt;The parameters are optional but give you an easy option to extend the user type to use your own algorithm.&lt;/p&gt;&lt;p&gt;The encryptor paramater expects an implementation of IEncryptor, if you don’t set it you get the uNHAddinsEncryptor implementation. Implementing the interface is very easy you just need to say how you encrypt and decrypt and if you want to use an external key set in the typedef parameters then you can get this using the EncryptionKey property.&lt;/p&gt;&lt;pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;interface&lt;/span&gt; IEncryptor&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;{&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;  &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;string&lt;/span&gt; Encrypt(&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;string&lt;/span&gt; password);&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;  &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;string&lt;/span&gt; Decrypt(&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;string&lt;/span&gt; encryptedPassword);&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;  &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;string&lt;/span&gt; EncryptionKey { &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;set&lt;/span&gt;; }&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;}&lt;/pre&gt;&lt;/pre&gt;&lt;p&gt;Using it now in your code is as easy as:&lt;/p&gt;&lt;pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;property&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;name&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;Password&quot;&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;type&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;Encrypted&quot;&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;p&gt;The Password property keeps being implemented as a string, so you don’t touch your existing code.&lt;/p&gt;</description><link>http://gustavoringel.blogspot.com/2009/02/encrypting-password-or-other-strings-in.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-6934655316762607435</guid><pubDate>Mon, 16 Feb 2009 09:50:00 +0000</pubDate><atom:updated>2009-02-16T16:11:28.826+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">svn</category><title>Changing a log entry using svn</title><description>&lt;p&gt;&lt;font size=&quot;1&quot;&gt;Warn: This is more a personal reminder, than a post…but someone may find it useful&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Today i was working in two solutions at the same time, and committed one of them thinking I’m committing the other one…dumb of me.&lt;/p&gt;  &lt;p&gt;So, i thought ok, big deal, went to the tortoise log and changed the log message, when I tried to change it, received this nice message box:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;http://lh4.ggpht.com/_eme11R-Ui2Y/SZk284lfrLI/AAAAAAAAAco/3z3NfEokFnM/s1600-h/image%5B3%5D.png&quot;&gt;&lt;img title=&quot;image&quot; style=&quot;border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px&quot; height=&quot;76&quot; alt=&quot;image&quot; src=&quot;http://lh5.ggpht.com/_eme11R-Ui2Y/SZk29784vbI/AAAAAAAAAcs/S-y3xeZBPGc/image_thumb%5B1%5D.png?imgmax=800&quot; width=&quot;274&quot; border=&quot;0&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Ok, first i found a template at the hooks directory of the repository called pre-revprop-change.tmpl which i can use to explicitly say that an specific revision was changed. This is the best solution as far as i read because every notification, etc will work as usual. But i did want to continue working and solve this error fast, and for now i’m not concerned in bypassing this for a while.&lt;/p&gt;  &lt;p&gt;So i found this line i can execute in svn to bypass the hooks:&lt;/p&gt;  &lt;p&gt;svnadmin setlog --bypass-hooks REPOS_PATH -r N&lt;/p&gt;  &lt;p&gt;Where REPOS_PATH is the local path for a subversion repository (i executed this in the server) and N is the number of the revision…&lt;/p&gt;  &lt;p&gt;I almost never had to do this, but i put me a reminder if a i need it in the future.&lt;/p&gt;  </description><link>http://gustavoringel.blogspot.com/2009/02/changing-log-entry-using-svn.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/_eme11R-Ui2Y/SZk29784vbI/AAAAAAAAAcs/S-y3xeZBPGc/s72-c/image_thumb%5B1%5D.png?imgmax=800" height="72" width="72"/><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-8083544275057748550</guid><pubDate>Sat, 14 Feb 2009 21:30:00 +0000</pubDate><atom:updated>2009-02-14T23:30:01.981+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">NHibernate</category><title>Why I like to work with NHibernate trunk…</title><description>&lt;p&gt;Last days i was using for several times the syntax SetParameter&amp;lt;T&amp;gt;(string, object). The code for this is a shortcut to SetParameter(string, object, IType).&lt;/p&gt;  &lt;p&gt;Using it in code in the first option looks like SetParameter&amp;lt;Entity&amp;gt;(“param”, value)&lt;/p&gt;  &lt;p&gt;The second syntax will be SetParameter(“param”, value, NHibernateUtil.Entity(tyepof(Entity))&lt;/p&gt;  &lt;p&gt;I’m almost sure for every one the first syntax will be prettier than the second one, I need to know and remember that NHibernateUtil also…&lt;/p&gt;  &lt;p&gt;I can download de trunk and run the tests…so i know that mostly every thing that worked will still work. I get the syntactic sugar and new fuctionalty for my current code…good enough.&lt;/p&gt;  &lt;p&gt;The only drawback…when i have to maintain code not using the trunk i suffer a little more.&lt;/p&gt;  </description><link>http://gustavoringel.blogspot.com/2009/02/why-i-like-to-work-with-nhibernate.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-5854027581823275228</guid><pubDate>Thu, 12 Feb 2009 23:06:00 +0000</pubDate><atom:updated>2009-02-13T01:08:46.514+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Conversation</category><category domain="http://www.blogger.com/atom/ns#">NHibernate</category><category domain="http://www.blogger.com/atom/ns#">Session</category><category domain="http://www.blogger.com/atom/ns#">uNHAddins</category><category domain="http://www.blogger.com/atom/ns#">Windows Forms</category><title>Changing the default conversation factory for uNHAddins</title><description>&lt;p&gt;Before i started using the uNHAddins conversation i was using Castle ATM + NHibernate Integration. In some cases i did have to execute an action immediately after the transaction is committed. I did this enlisting an ISynchronize object to the ITransactionManager and then Castle handled this call.&lt;/p&gt;  &lt;p&gt;Now i was in the need of doing the same thing using uNHAddins. I chatted a little bit with Fabio, and at the end we found that it is very easy to extend uNHAddins to have this behavior. All i had to do was implementing my own ConversationFactory, i decided to call it NotifiableConversationFactory.&lt;/p&gt;  &lt;p&gt;My implementation is:&lt;/p&gt;  &lt;pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;class&lt;/span&gt; NotifiableConversationFactory : IConversationFactory&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt; {&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;  &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;readonly&lt;/span&gt; ISessionFactoryProvider factoriesProvider;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;  &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;readonly&lt;/span&gt; ISessionWrapper wrapper;&lt;br /&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;  &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; NotifiableConversationFactory(ISessionFactoryProvider factoriesProvider, ISessionWrapper wrapper)&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;  {&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;   &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;this&lt;/span&gt;.factoriesProvider = factoriesProvider;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;   &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;this&lt;/span&gt;.wrapper = wrapper;&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;  }&lt;br /&gt;&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;  &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; IConversation CreateConversation()&lt;br /&gt;&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;  {&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;   &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;new&lt;/span&gt; NhConversation(factoriesProvider, wrapper);&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;  }&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;  &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; IConversation CreateConversation(&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;string&lt;/span&gt; conversationId)&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;  {&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;   var result = &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;new&lt;/span&gt; NhConversation(factoriesProvider, wrapper, conversationId);&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;   &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;if&lt;/span&gt; (conversationId.StartsWith(&quot;&lt;span style=&quot;color: rgb(139, 0, 0);&quot;&gt;Notify&lt;/span&gt;&quot;))&lt;br /&gt;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;   {&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;    result.Ended += EventSource.Conversation_Ended;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;   }&lt;br /&gt;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;   &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;return&lt;/span&gt; result;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;  }&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt; }&lt;/pre&gt;&lt;/pre&gt;&lt;p&gt;I’m not so happy about the string “Notify” there but this is more a proof of concept than a real implementation.&lt;/p&gt;&lt;p&gt;What i’m checking there is if i’m called by a conversation with IdPrefix = “Notify”. IdPrefix is a handy property of PersistenceConversational which permits adding a prefix to the conversation id so i can detect if this conversation is some type of conversation i prefix this way.&lt;/p&gt;&lt;p&gt;So in the class you want to register the events you must have:&lt;/p&gt;&lt;p&gt;[PersistenceConversational(IdPrefix = &quot;Notify&quot;)]&lt;/p&gt;&lt;p&gt;An example as always can be find in the &lt;a href=&quot;http://unhaddins.googlecode.com/svn/trunk/Examples/uNHAddins.Examples.SessionManagement/&quot; target=&quot;_blank&quot;&gt;sessionManagement example&lt;/a&gt; at uNHAddins. The IModifyOrderModel is notifying (log) about the end of the conversation.&lt;/p&gt;</description><link>http://gustavoringel.blogspot.com/2009/02/changing-default-conversation-factory.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-4465712568494014794</guid><pubDate>Sun, 08 Feb 2009 20:56:00 +0000</pubDate><atom:updated>2009-05-12T00:39:40.088+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Conversation</category><category domain="http://www.blogger.com/atom/ns#">NHibernate</category><category domain="http://www.blogger.com/atom/ns#">Session</category><category domain="http://www.blogger.com/atom/ns#">uNHAddins</category><category domain="http://www.blogger.com/atom/ns#">Windows Forms</category><title>uNHAddins Persistence Conversation – Part 2: Configuring the conversation</title><description>&lt;p&gt;In the &lt;a href=&quot;http://gustavoringel.blogspot.com/2009/02/unhaddins-persistence-conversation-part.html&quot; target=&quot;_blank&quot;&gt;first post&lt;/a&gt; I showed how to configure the uNHAddins conversation. Now I will show how to use the PersistenceConversation aspects to manage a uNHAddins conversation.&lt;/p&gt;  &lt;p&gt;A class which will rule a conversation should be marked as [PersistenceConversational] every public method that is part of a conversation should be marked as [PersistenceConversation]. &lt;/p&gt;  &lt;p&gt;In the example code we have the interface &lt;/p&gt;  &lt;pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;interface&lt;/span&gt; IModifyOrderModel&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;{&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;  PurchaseOrder FindOrderOrCreateNew(&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;string&lt;/span&gt; number, DateTime dateTime);&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;  &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;void&lt;/span&gt; Persist(PurchaseOrder order);&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;  &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;void&lt;/span&gt; AbortConversation();&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;}&lt;/pre&gt;&lt;/pre&gt;which is implemented by the ModifyOrderModel class:&lt;br /&gt;&lt;pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;[PersistenceConversational]&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;class&lt;/span&gt; ModifyOrderModel : IModifyOrderModel&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;{&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;readonly&lt;/span&gt; IOrderRepository orderRepository;&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; ModifyOrderModel(IOrderRepository orderRepository)&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;{&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&lt;span style=&quot;color: rgb(51, 51, 51);&quot;&gt;  &lt;/span&gt;this&lt;/span&gt;.orderRepository = orderRepository;&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;}&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;[PersistenceConversation(ConversationEndMode = EndMode.Abort)]&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;void&lt;/span&gt; AbortConversation()&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;{&lt;span style=&quot;color: rgb(0, 128, 0);&quot;&gt;&lt;span style=&quot;color: rgb(51, 51, 51);&quot;&gt;  &lt;/span&gt;// Rollback the use case &lt;/span&gt;}&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;[PersistenceConversation]&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; PurchaseOrder FindOrderOrCreateNew(&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;string&lt;/span&gt; number, DateTime dateTime)&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;{&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;  var order = orderRepository.GetOrderByNumberAndDate(number, dateTime.Date);&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;  if&lt;/span&gt; (order == &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;null&lt;/span&gt;)&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;  { order = &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;new&lt;/span&gt; PurchaseOrder { Date = dateTime, Number = number }; }&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;  return&lt;/span&gt; order;&lt;/p&gt;&lt;p&gt;}&lt;br /&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;   [PersistenceConversation(ConversationEndMode = EndMode.End)]&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&lt;span style=&quot;color: rgb(51, 51, 51);&quot;&gt;   &lt;/span&gt;public&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;void&lt;/span&gt; Persist(PurchaseOrder order)&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;   {&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;&lt;blockquote&gt;&lt;p&gt;   orderRepository.MakePersistent(order);&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;   }&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;}&lt;/pre&gt;&lt;/pre&gt;&lt;p&gt;This class manages the order modification conversation. As you see we don’t have references to NHibernate at this point. We do have an IOrderRepository which is going to provide the data we need for the conversation.&lt;/p&gt;&lt;p&gt;The implementation of the repository in the example is very simple, one important thing to notice is that we are injecting an ISessionFactory:&lt;/p&gt;&lt;pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;class&lt;/span&gt; OrderRepository : Repository&amp;lt;PurchaseOrder&amp;gt;, IOrderRepository&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;{&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; OrderRepository(ISessionFactory sessionFactory) : &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;base&lt;/span&gt;(sessionFactory) { }&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;public&lt;/span&gt; PurchaseOrder GetOrderByNumberAndDate(&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;string&lt;/span&gt; number, DateTime dateTime)&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;&lt;blockquote&gt;&lt;p&gt;{&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt; var query = Session.GetNamedQuery(&quot;&lt;span style=&quot;color: rgb(139, 0, 0);&quot;&gt;GetOrderByNumberAndDate&lt;/span&gt;&quot;).SetParameter(&quot;&lt;span style=&quot;color: rgb(139, 0, 0);&quot;&gt;number&lt;/span&gt;&quot;, number).SetParameter(&quot;&lt;span style=&quot;color: rgb(139, 0, 0);&quot;&gt;dateTime&lt;/span&gt;&quot;, dateTime); &lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt; &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;return&lt;/span&gt; query.UniqueResult&amp;lt;PurchaseOrder&amp;gt;();&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;&lt;blockquote&gt;&lt;p&gt;}&lt;/p&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;}&lt;/pre&gt;&lt;/pre&gt;The Repository&amp;lt;T&amp;gt; is a very thin class which gives minimum CRUD implementations using NH. The interesting part is how we are getting a session:&lt;br /&gt;&lt;pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;protected&lt;/span&gt; ISession Session&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;{&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;  &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;get&lt;/span&gt; { &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;return&lt;/span&gt; factory.GetCurrentSession(); }&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; font-size: 12px; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: rgb(255, 255, 255);&quot;&gt;}&lt;/pre&gt;&lt;/pre&gt;&lt;p&gt;From the doc: GetCurrentSession() Obtains the current session. The definition of what exactly &quot;current&quot; means controlled by the &lt;a href=&quot;http://www.hibernate.org/hib_docs/v3/api/org/hibernate/context/CurrentSessionContext.html&quot;&gt;&lt;code&gt;CurrentSessionContext&lt;/code&gt;&lt;/a&gt; impl configured for use&lt;/p&gt;&lt;p&gt;In our case if you remember from the &lt;a href=&quot;http://gustavoringel.blogspot.com/2009/02/unhaddins-persistence-conversation-part.html&quot; target=&quot;_blank&quot;&gt;first post&lt;/a&gt; we are using the uNHAddins &lt;a href=&quot;http://www.hibernate.org/hib_docs/v3/api/org/hibernate/context/CurrentSessionContext.html&quot;&gt;&lt;code&gt;ThreadLocalConversationalSessionContext&lt;/code&gt;&lt;/a&gt;, which in general is good enough for a Windows Forms Application.&lt;/p&gt;You may have noticed a property ConversationalEndMode in the PersistenceConversation attribute, for now there are three options:&lt;br /&gt;&lt;p&gt;EndMode.Continue: Can start a conversation and lives it alive.&lt;/p&gt;&lt;p&gt;EndMode.End: Flushes the session and commits current transactions, then it disposes the session&lt;/p&gt;&lt;p&gt;EndMode.Abort: Disposes the session (without accepting the changes)&lt;/p&gt;Basically this is it. In the &lt;a href=&quot;http://unhaddins.googlecode.com/svn/trunk/Examples/uNHAddins.Examples.SessionManagement/&quot; target=&quot;_blank&quot;&gt;example code&lt;/a&gt; you can find an application using MVP with this ideas. Feel free to comment / ask in the &lt;a href=&quot;http://groups.google.com/group/unhaddins&quot; target=&quot;_blank&quot;&gt;uNHAddins forum&lt;/a&gt; about it.</description><link>http://gustavoringel.blogspot.com/2009/02/unhaddins-persistence-conversation-part_08.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>16</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8757739037105656062.post-4990154129998911867</guid><pubDate>Fri, 06 Feb 2009 16:53:00 +0000</pubDate><atom:updated>2009-05-12T00:38:57.768+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Conversation</category><category domain="http://www.blogger.com/atom/ns#">NHibernate</category><category domain="http://www.blogger.com/atom/ns#">Session</category><category domain="http://www.blogger.com/atom/ns#">uNHAddins</category><category domain="http://www.blogger.com/atom/ns#">Windows Forms</category><title>uNHaddins Persistence Conversation – Part 1: Configuration</title><description>&lt;p&gt;uNHAddins Conversation and motivations where widely presented on Fabio’s blog &lt;a href=&quot;http://fabiomaulo.blogspot.com/2009/01/aspect-conversation-per.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The focus of this series of posts is configuring the Persistence Conversation aspect using uNHAddins and CastleAdapter targeting a Windows Forms Application (some of the concepts are easily movable to a Web application, but there are much more frameworks and examples matching this)&lt;/p&gt;  &lt;p&gt;A working example can be found in the examples folder of &lt;a href=&quot;http://groups.google.com/group/unhaddins&quot; target=&quot;_blank&quot;&gt;uNHAddins&lt;/a&gt; trunk, &lt;a href=&quot;http://unhaddins.googlecode.com/svn/trunk/Examples/uNHAddins.Examples.SessionManagement/&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The following assumptions are made about your repositories/Dao’s for this to work. &lt;/p&gt;  &lt;p&gt;1) You are injecting the ISessionFactory in the repositories and not an ISession. &lt;/p&gt;  &lt;p&gt;2) You are using GetCurrentSession() instead of OpenSession() to get the active session inside the repositories / dao’s.&lt;/p&gt;  &lt;p&gt;3) You are able to use Castle for Dependency Injection, i hope more adapters will come in the future, but this is one that it is implemented and it is enough popular.&lt;/p&gt;  &lt;p&gt;First thing we should do is to decide the conversation context strategy and set it in the hibernate cfg. For this example it is:&lt;/p&gt;  &lt;pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;property&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;name&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;current_session_context_class&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;uNhAddIns.SessionEasier.Conversations.ThreadLocalConversationalSessionContext, uNhAddIns &lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;property&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;p&gt;Next thing is configuring castle to accept the PersistenceConversationalFacility, which will bring AOP in a similar manner to the TransactionalFacility from castle, and all the factories and services that compose a conversation.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;The configuration for the facilities and default uNHAddins components for Castle can be found &lt;a href=&quot;http://unhaddins.googlecode.com/svn/trunk/Examples/uNHAddins.Examples.SessionManagement/SessionManagement.Infrastructure/uNhAddIns-PersistenceConversation-nh-default.config&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt; . There are some cases when you will want to play with the factories, this will be the reason for another post.&lt;br /&gt;&lt;/p&gt;Finally you set the way you are going to create sessions in your application (sessionFactory provider is the id to an implementation of ISessionFactoryProvider)&lt;br /&gt;&lt;pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;component&lt;/span&gt; &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;id&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;uNhAddIns.sessionFactory&quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;      &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;type&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;NHibernate.ISessionFactory, NHibernate&quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;      &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;factoryId&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;sessionFactoryProvider&quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;      &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;factoryCreate&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&quot;GetFactory&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;      &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;parameters&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre   style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);font-family:consolas,&#39;Courier New&#39;,courier,monospace;font-size:12px;&quot;&gt;        &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;factoryId&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt;uNhAddIns&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;factoryId&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255); font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px;&quot;&gt;      &lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;parameters&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre face=&quot;consolas,&#39;Courier New&#39;,courier,monospace&quot; size=&quot;12px&quot; style=&quot;margin: 0em; width: 100%; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;This is all the magic we need to set it up all. The following post will be about using it in our application.&lt;br /&gt;&lt;br /&gt;If you want to see it working follow the link to the source at the beginning of the post.</description><link>http://gustavoringel.blogspot.com/2009/02/unhaddins-persistence-conversation-part.html</link><author>noreply@blogger.com (Gustavo Ringel)</author><thr:total>2</thr:total></item></channel></rss>