<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>PrimordialCode</title><link>http://www.primordialcode.com/</link><description>Where Mammoths runs wild on your mind!</description><copyright>Giorgetti Alessandro</copyright><docs>http://www.rssboard.org/rss-specification</docs><generator>http://dexterblogengine.codeplex.com</generator><language>en-GB</language><lastBuildDate>Fri, 24 Feb 2012 14:47:24 GMT</lastBuildDate><webMaster>Guardian</webMaster><category>.Net NHibernate Wpf Silverlight Windows Phone</category><feedburner:info uri="primordialcode" /><creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license><image><url>http://www.feedburner.com/fb/images/pub/fb_pwrd.gif</url></image><feedburner:feedFlare href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.feedburner.com%2FPrimordialCode" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare href="http://www.thefreedictionary.com/_/hp/AddRSS.aspx?http%3A%2F%2Ffeeds.feedburner.com%2FPrimordialCode" src="http://img.tfd.com/hp/addToTheFreeDictionary.gif">Subscribe with The Free Dictionary</feedburner:feedFlare><feedburner:feedFlare href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Ffeeds.feedburner.com%2FPrimordialCode" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2FPrimordialCode" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare href="http://mix.excite.eu/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FPrimordialCode" src="http://image.excite.co.uk/mix/addtomix.gif">Subscribe with Excite MIX</feedburner:feedFlare><feedburner:feedFlare href="http://www.webwag.com/wwgthis.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FPrimordialCode" src="http://www.webwag.com/images/wwgthis.gif">Subscribe with Webwag</feedburner:feedFlare><feedburner:feedFlare href="http://www.podcastready.com/oneclick_bookmark.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FPrimordialCode" src="http://www.podcastready.com/images/podcastready_button.gif">Subscribe with Podcast Ready</feedburner:feedFlare><feedburner:feedFlare href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.feedburner.com%2FPrimordialCode" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare href="http://www.dailyrotation.com/index.php?feed=http%3A%2F%2Ffeeds.feedburner.com%2FPrimordialCode" src="http://www.dailyrotation.com/rss-dr2.gif">Subscribe with Daily Rotation</feedburner:feedFlare><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/GuardiansHome" /><feedburner:info uri="guardianshome" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:feedFlare href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.feedburner.com%2FGuardiansHome" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare href="http://www.thefreedictionary.com/_/hp/AddRSS.aspx?http%3A%2F%2Ffeeds.feedburner.com%2FGuardiansHome" src="http://img.tfd.com/hp/addToTheFreeDictionary.gif">Subscribe with The Free Dictionary</feedburner:feedFlare><feedburner:feedFlare href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Ffeeds.feedburner.com%2FGuardiansHome" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2FGuardiansHome" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare href="http://mix.excite.eu/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FGuardiansHome" src="http://image.excite.co.uk/mix/addtomix.gif">Subscribe with Excite MIX</feedburner:feedFlare><feedburner:feedFlare href="http://www.webwag.com/wwgthis.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FGuardiansHome" src="http://www.webwag.com/images/wwgthis.gif">Subscribe with Webwag</feedburner:feedFlare><feedburner:feedFlare href="http://www.podcastready.com/oneclick_bookmark.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FGuardiansHome" src="http://www.podcastready.com/images/podcastready_button.gif">Subscribe with Podcast Ready</feedburner:feedFlare><feedburner:feedFlare href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.feedburner.com%2FGuardiansHome" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare href="http://www.dailyrotation.com/index.php?feed=http%3A%2F%2Ffeeds.feedburner.com%2FGuardiansHome" src="http://www.dailyrotation.com/rss-dr2.gif">Subscribe with Daily Rotation</feedburner:feedFlare><item><title>WP7 - Test if your ViewModel is serializable</title><description>&lt;p&gt;Writing WP7 applications (and the new Metro UI Apps in Windows 8) you will have to deal with concepts like ‘Tombstoning’ or ‘Suspension’; if you follow the MVVM pattern, there’s a very good chance that the status of your application page is represented by the ViewModel itself. So a quick and dirty way to handle those suspended states is to ‘persist’ the ViewModel (or the part of it that have actual meaning) to the application state or to a file storage and retrieve it at a later time when the application is reactivated.&lt;/p&gt;  &lt;p&gt;if you put something that is not a primitive type inside the Application State or the Page State dictionaries, it will be serialized using the standard DataContractSerializer (on the subject of serialization and deserialization in WP7 you can read these previous posts of mine: &lt;a href="http://www.primordialcode.com/blog/post/wp7-understanding-serialization"&gt;WP7 Understanding Serialization&lt;/a&gt; and &lt;a href="http://www.primordialcode.com/blog/post/wp7-datacontractserializer-bug"&gt;http://www.primordialcode.com/blog/post/wp7-datacontractserializer-bug&lt;/a&gt;).&lt;/p&gt;  &lt;p&gt;A good way to avoid headaches when using this approach to handle tombstoning/suspension is the to test not only the behavior of your ViewModels, but also if your ViewModels are serializable; you can do this by using an helper class similar to this one:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:16fb496c-f3cc-41a4-bf93-079c84f2d5aa" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: csharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: true;  width: 600px; height: 400px;" style=" width: 600px; height: 400px;overflow: auto;"&gt;public static class DataContractSerializerHelpers
{
    public static string ToXml(object obj)
    {
        return ToXml(obj, null);
    }

    public static string ToXml(object obj, IEnumerable&amp;lt;Type&amp;gt; knownTypes)
    {
        Type objType = obj.GetType();
        DataContractSerializer ser = new DataContractSerializer(objType, knownTypes);
        {
            using (StringWriter sw = new StringWriter())
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.OmitXmlDeclaration = true;
                settings.Indent = true;
                //settings.NewLineOnAttributes = true;
                using (XmlWriter writer = XmlWriter.Create(sw, settings))
                {
                    ser.WriteObject(writer, obj);
                }
                return sw.ToString();
            }
        }
    }

    public static object FromXml(string data, Type type)
    {
        return FromXml(data, type, null);
    }

    public static object FromXml(string data, Type type, IEnumerable&amp;lt;Type&amp;gt; knownTypes)
    {
        using (StringReader sr = new StringReader(data))
        {
            XmlReaderSettings settings = new XmlReaderSettings();
            using (XmlReader reader = XmlReader.Create(sr, settings))
            {
                DataContractSerializer ser = new DataContractSerializer(type, knownTypes);
                return ser.ReadObject(reader);
            }
        }
    }

    public static T FromXml&amp;lt;T&amp;gt;(string data) where T : class
    {
        return FromXml(data, typeof(T), null) as T;
    }

    public static T FromXml&amp;lt;T&amp;gt;(string data, IEnumerable&amp;lt;Type&amp;gt; extraTypes) where T : class
    {
        return FromXml(data, typeof(T), extraTypes) as T;
    }
}&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;It’s basically a simple wrapper around the DataContractSerializer function to call it in a convenient way that mimic what the infrastructure does.&lt;/p&gt;

&lt;p&gt;Using the standard DataContractAttribute and DataMemberAttribute on the ViewModels you can fine tune what will be persisted (obviously you should limit this to the properties that have some meaning for your application state, you will also have to design the ViewModels to provide lazy initialization for everything that depends on those data). Your tests will then look similar to this one:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:67edae9b-bcd9-421a-b831-bf66c9b3353d" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: csharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: true;  width: 600px; height: 400px;" style=" width: 600px; height: 400px;overflow: auto;"&gt;[TestClass]
public class SerializableTypes : SilverlightTest
{
    // Test if we can save the VM to the state dictionaries
	[TestMethod]
    public void ViewModel_Serialize()
    {
		// todo: add proper members initialization
	    MainViewModel vm = new MainViewModel();
        DataContractSerializerHelpers.ToXml(vm);
    }

	// Test if we can retrieve the VM from the state dictionaries
    [TestMethod]
    public void ViewModel_DeSerialize()
    {
		// todo: add proper members initialization
	    MainViewModel vm = new MainViewModel();
        var data = DataContractSerializerHelpers.ToXml(vm);

        // test
        var loaded = DataContractSerializerHelpers.FromXml&amp;lt;MainViewModel&amp;gt;(data);
        Assert.IsNotNull(loaded);
		// todo: add proper testing on members values
    }
}&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;With this approach the code that you have to write on the views to handle tombstoning will become trivial; in your views you will have something similar to this:&lt;/p&gt;

&lt;p&gt;
  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:e465136c-396b-4fe6-a4db-ecdf6936b9bf" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: csharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: true;  width: 600px; height: 400px;" style=" width: 600px; height: 400px;overflow: auto;"&gt;...

private SingleFeedViewModel Vm
{
    get { return (SingleFeedViewModel)DataContext; }
    set { DataContext = value; }
}

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo(e);

    // if we came up after a dormant state we do not need to do anything at this stage
    // I also have to check if the Vm is unassigned (we can come here from a normal navigation, after a resume)
    if (ApplicationHelper.IsApplicationInstancePreserved &amp;amp;&amp;amp; Vm != null)
        return;

    // recover from tombstoning
    if (State.ContainsKey(StateKeys.SingleFeedVm))
	{
		//clear prev value
		SingleFeedViewModel itm = State[StateKeys.SingleFeedVm] as SingleFeedViewModel;
		if (itm != null)
		    Vm = itm;
	}
    // nothing was retrieved from the state dictionary, create an instance
	// of the ViewModel
    if (Vm == null)
    {
        Vm = new SingleFeedViewModel();
        Vm.LoadData();
    }
}

protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedFrom(e);
    // save state to handle tombstoning
    if (State.ContainsKey(StateKeys.SingleFeedVm))
    {
        //clear previous value
        State.Remove(StateKeys.SingleFeedVm);
    }
    State.Add(StateKeys.SingleFeedVm, Vm);
}

...&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;
&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;WARNING! I was about to forget an important point: &lt;strong&gt;events cannot be serialized&lt;/strong&gt; (once again a reference to another old post of mine: &lt;a href="http://www.primordialcode.com/blog/post/serialization-exception-propertychangedeventmanager-serializable"&gt;Serialization Exception: PropertyChangedEventManager is not serializable&lt;/a&gt;, it’s related to binary serialization or objects, but the concept is the same), so remember to not mark the events with the DataMemberAttribute or, if your ViewModel has everything public, and you didn’t used the DataContractAttribute to opt-in what you want to be serialized, it’s better to mark the events with [field: IgnoreDataMember] to exclude them from the serialization process.&lt;/p&gt;&lt;h2&gt;Related Content&lt;/h2&gt;&lt;ul&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/wp7-unit-testing-getting-started"&gt;WP7 Unit Testing - getting started&lt;/a&gt; (2/22/2012)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="/Blog/Related/wp7-test-if-your-viewmodel-is-serializable"&gt;&lt;strong&gt;More related document (1)&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=2S80EPPHwBo:a3sB1HKHphs:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=2S80EPPHwBo:a3sB1HKHphs:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=2S80EPPHwBo:a3sB1HKHphs:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=2S80EPPHwBo:a3sB1HKHphs:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=2S80EPPHwBo:a3sB1HKHphs:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=2S80EPPHwBo:a3sB1HKHphs:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=2S80EPPHwBo:a3sB1HKHphs:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=2S80EPPHwBo:a3sB1HKHphs:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=2S80EPPHwBo:a3sB1HKHphs:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/PrimordialCode/~4/2S80EPPHwBo" height="1" width="1"/&gt;&lt;img src="http://feeds.feedburner.com/~r/GuardiansHome/~4/3F6QyhpwSTc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/GuardiansHome/~3/3F6QyhpwSTc/wp7-test-if-your-viewmodel-is-serializable</link><author>guardian</author><comments>http://www.primordialcode.com/blog/post/wp7-test-if-your-viewmodel-is-serializable#feedback</comments><guid isPermaLink="false">http://www.primordialcode.com/blog/post/wp7-test-if-your-viewmodel-is-serializable</guid><pubDate>Fri, 24 Feb 2012 22:47:24 GMT</pubDate><category>WP7</category><category>Unit Test</category><feedburner:origLink>http://www.primordialcode.com/blog/post/wp7-test-if-your-viewmodel-is-serializable</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/PrimordialCode/~3/2S80EPPHwBo/wp7-test-if-your-viewmodel-is-serializable</feedburner:origLink></item><item><title>WP7 Unit Testing - getting started</title><description>&lt;p&gt;Testing is important and it can save you lots of time, to successfully setup a WP7 Unit Test project I recommend you to first obtain the ‘NuGet Package Manager’ Visual Studio 2010 extension, it will make it a breeze to retrieve the latest version of libraries and packages and add a reference to them.&lt;/p&gt;  &lt;p&gt;Here is a step by step guide on how to create your test project using the testing framework kindly provided to us by &lt;a href="http://www.jeff.wilcox.name/"&gt;Jeff Wilcox&lt;/a&gt;:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Open up Visual Studio and install NuGet if you do not have it: Tools –&amp;gt; Extension Manager, look for NuGet Package Manager in the Online Gallery. &lt;/li&gt;    &lt;li&gt;Create a new Windows Phone Application project, do not modify it right now. &lt;/li&gt;    &lt;li&gt;Use NuGet to get the latest version of the Unit Test framework for WP7, you can do it in two ways:&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; - for the ‘Tools’ menu chose ‘Library Package Manager’ and then ‘Manage NuGet Packages for Solution’      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; - right click on the project you wish the package to be added to and select ‘Manage NuGet Packages’&lt;/li&gt;    &lt;li&gt;In the dialog that will open go to the Online section and look for ‘silverlight.unittest.wp7’     &lt;br /&gt;&lt;a href="http://www.primordialcode.com/UserFiles/guardian/NuGetSlUnitTestWP7.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 4px 10px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="NuGetSlUnitTestWP7" border="0" alt="NuGetSlUnitTestWP7" src="http://www.primordialcode.com/UserFiles/guardian/NuGetSlUnitTestWP7_thumb.png" width="554" height="311" /&gt;&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;click on ‘install’ to download and add the package to the selected project.&lt;/li&gt;    &lt;li&gt;it’s time to modify the test project following what’s written in the Test_Readme.txt file:     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; - open up the MainPage.xaml and handle the ‘Loaded’ event      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; - add the following line to the event to activate the test infrastructure: this.StartTestRunner();&lt;/li&gt;    &lt;li&gt;Done. Running the project you should see something like this:     &lt;br /&gt;&lt;a href="http://www.primordialcode.com/UserFiles/guardian/WP7ut1_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 4px 10px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="WP7ut1" border="0" alt="WP7ut1" src="http://www.primordialcode.com/UserFiles/guardian/WP7ut1_thumb.png" width="204" height="337" /&gt;&lt;/a&gt;&lt;a href="http://www.primordialcode.com/UserFiles/guardian/WP7ut2_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 4px 10px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="WP7ut2" border="0" alt="WP7ut2" src="http://www.primordialcode.com/UserFiles/guardian/WP7ut2_thumb.png" width="204" height="337" /&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;You are now ready to write you own custom tests using a syntax and rules very similar the ones used by the MSTest suite that is already integrated in Visual Studio.&lt;/p&gt;&lt;h2&gt;Related Content&lt;/h2&gt;&lt;ul&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/wp7-test-if-your-viewmodel-is-serializable"&gt;WP7 - Test if your ViewModel is serializable&lt;/a&gt; (2/24/2012)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="/Blog/Related/wp7-unit-testing-getting-started"&gt;&lt;strong&gt;More related document (1)&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=8c7Hf46aEZo:dAGkzwwgRdw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=8c7Hf46aEZo:dAGkzwwgRdw:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=8c7Hf46aEZo:dAGkzwwgRdw:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=8c7Hf46aEZo:dAGkzwwgRdw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=8c7Hf46aEZo:dAGkzwwgRdw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=8c7Hf46aEZo:dAGkzwwgRdw:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=8c7Hf46aEZo:dAGkzwwgRdw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=8c7Hf46aEZo:dAGkzwwgRdw:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=8c7Hf46aEZo:dAGkzwwgRdw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/PrimordialCode/~4/8c7Hf46aEZo" height="1" width="1"/&gt;&lt;img src="http://feeds.feedburner.com/~r/GuardiansHome/~4/7B5-RgtPsZ0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/GuardiansHome/~3/7B5-RgtPsZ0/wp7-unit-testing-getting-started</link><author>guardian</author><comments>http://www.primordialcode.com/blog/post/wp7-unit-testing-getting-started#feedback</comments><guid isPermaLink="false">http://www.primordialcode.com/blog/post/wp7-unit-testing-getting-started</guid><pubDate>Wed, 22 Feb 2012 20:26:26 GMT</pubDate><category>WP7</category><category>Unit Test</category><feedburner:origLink>http://www.primordialcode.com/blog/post/wp7-unit-testing-getting-started</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/PrimordialCode/~3/8c7Hf46aEZo/wp7-unit-testing-getting-started</feedburner:origLink></item><item><title>Configure WebMatrix/IIS Express to work with WP7 on Windows 7</title><description>&lt;p&gt;Long time is passed after my last ‘notable’ blog post, I was just too busy and lazy in the past months, lots of things happened and I couldn’t follow everything, but it’s not that I want to talk about, let’s talk about some more WP7 development.&lt;/p&gt;  &lt;p&gt;Actually I am ‘playing’ with WP7, jQuery Mobile, WCF services and some various mobile stuff these days, honestly I was tired of having my WP7 device connected to the USB cable in order to be able to surf websites and use services that are hosted on my development machine. So I started to scouting around looking for a solution.&lt;/p&gt;  &lt;p&gt;My goal is to be able to host websites and WCF services using WebMatrix ad IIS Express at first and a custom made WCF self hosting solution at a later time for my developing everyday life (and for demo purposes).&lt;/p&gt;  &lt;p&gt;So here’s my current setup:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;IIS Express/WebMatrix &lt;/li&gt;    &lt;li&gt;Zune &lt;/li&gt;    &lt;li&gt;WP7 + USB cable connected &lt;/li&gt;    &lt;li&gt;a fantastic website hosted on IIS Express &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Everything is working correctly here, I can browse the website from WP7 and test it, but I have to keep the cable connected, which is a no go if I want to make a demo of something to someone with a ‘floating’ device. I do not want to create new DNS entries, nor touch the network infrastructure nor do any other complicated IT or network related stuff, that’s not for me.&lt;/p&gt;  &lt;p&gt;I want to be able to switch to this setup (both for testing and demo environment):&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;IIS Express/WebMatrix &lt;/li&gt;    &lt;li&gt;WP7 &lt;/li&gt;    &lt;li&gt;still my fantastic website hosted on IIS Express &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;you see: no Zune, no cable, just me and my device (and Visual Studio of course). To obtain this we need to make IIS Express able to accept connections from the outside, you can do that following this guide:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.iis.net/vaidyg/archive/2010/07/29/serving-external-traffic-with-webmatrix-beta.aspx"&gt;http://blogs.iis.net/vaidyg/archive/2010/07/29/serving-external-traffic-with-webmatrix-beta.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Here’s what I had to do in order to make things work:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Get your computer IP, mine was: 192.168.1.10. &lt;/li&gt;    &lt;li&gt;Pickup a port you will use to host your service (using port 80 is bad idea on a development machine), I choose: 24778. &lt;/li&gt;    &lt;li&gt;Configure HTTP.SYS (the component that is used to handle http requests) to accept external connection when running as standard user (you can bypass this if you launch WebMatrix and IIS Express with admin privileges, but that’s not good for security reasons), open a shell prompt with admin rights and type:      &lt;br /&gt;      &lt;br /&gt;      &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:1c12b135-8b7d-43fe-ac13-09d3ebe28a86" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: plain; gutter: true; first-line: 1; tab-size: 4;  toolbar: true; "&gt;netsh http add urlacl url=http://192.168.1.10:24778/ user=everyone
&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

    &lt;br /&gt;&lt;/li&gt;

  &lt;li&gt;Configure the binding in WebMatrix: doing it by manually editing the &lt;strong&gt;applicationhost.config&lt;/strong&gt; file is the best way. The file is located is your user profile at the following folder: “%USERPROFILE%\documents\IISExpress\config”. Another way to find it is: right click on the IIS Express icon in the system Tray, choose “show all applications”, highlight your website and then look at the configuration setting (it’s the last voice on the window), you can even click on it to open the file in notepad. 

    &lt;br /&gt;

    &lt;br /&gt;&lt;a href="http://www.primordialcode.com/UserFiles/Guardian/WebMatrixWp7_1.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 4px 10px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="WebMatrixWp7_1" border="0" alt="WebMatrixWp7_1" src="http://www.primordialcode.com/UserFiles/Guardian/WebMatrixWp7_1_thumb.png" width="687" height="278" /&gt;&lt;/a&gt; 

    &lt;br /&gt;The image is in Italian, I know &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-openmouthedsmile" alt="Open-mouthed smile" src="http://www.primordialcode.com/UserFiles/Guardian/wlEmoticon-openmouthedsmile_2_12.png" /&gt;; now that you have your file open you need to locate the your website configuration and change the binding settings to allow connection the pre-defined IP address and port. Here’s how I modified my configuration: 

    &lt;br /&gt;

    &lt;br /&gt;

    &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:d5968c44-a33d-414f-97b5-7195319b8adb" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: plain; gutter: true; first-line: 1; tab-size: 4;  toolbar: true; "&gt;&amp;lt;site name=&amp;quot;MyWonderfulSite&amp;quot; id=&amp;quot;2&amp;quot;&amp;gt;
 &amp;lt;application path=&amp;quot;/&amp;quot;&amp;gt;
     &amp;lt;virtualDirectory path=&amp;quot;/&amp;quot; physicalPath=&amp;quot;D:\XXXXXXXXXX&amp;quot; /&amp;gt;
 &amp;lt;/application&amp;gt;
 &amp;lt;bindings&amp;gt;
     &amp;lt;binding protocol=&amp;quot;http&amp;quot; bindingInformation=&amp;quot;*:24778:localhost&amp;quot; /&amp;gt;   
     &amp;lt;binding protocol=&amp;quot;http&amp;quot; bindingInformation=&amp;quot;192.168.1.10:24778:&amp;quot; /&amp;gt;   
 &amp;lt;/bindings&amp;gt;
&amp;lt;/site&amp;gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

    &lt;br /&gt;I have added a binding that explicitly configure the IP address and port that I want to use without assigning a hostname. 

    &lt;br /&gt;&lt;/li&gt;

  &lt;li&gt;The last step is to open up the port in your Firewall, this is up to you depending on the Firewall you are using. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;If you have followed all the steps you are now able to browse your test website (using the specified address like: &lt;a href="http://192.168.1.10:24778/"&gt;http://192.168.1.10:24778/&lt;/a&gt;) from your WP7 without having the USB cable connected and Zune open, pretty cool isn’t it ?&lt;/p&gt;

&lt;p&gt;These very same steps can be used for your Android and iPhone devices, but I personally do not own any of those devices so I wasn’t able to try it.&lt;/p&gt;

&lt;p&gt;Doing this research I’ve learned a couple of things about IIS Express and how the http requests are served by the system.&lt;/p&gt;

&lt;p&gt;As last note: to undo the modifications you’ve done to the HTTP.SYS configuration you can use the following command:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:4d6c501d-59eb-4e5d-8a55-b1cf587575f3" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: plain; gutter: true; first-line: 1; tab-size: 4;  toolbar: true; "&gt;netsh http delete urlacl url=http://192.168.1.10:24778/&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;See you next.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=TaUQCiF7unk:WuhGmeyULa4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=TaUQCiF7unk:WuhGmeyULa4:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=TaUQCiF7unk:WuhGmeyULa4:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=TaUQCiF7unk:WuhGmeyULa4:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=TaUQCiF7unk:WuhGmeyULa4:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=TaUQCiF7unk:WuhGmeyULa4:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=TaUQCiF7unk:WuhGmeyULa4:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=TaUQCiF7unk:WuhGmeyULa4:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=TaUQCiF7unk:WuhGmeyULa4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/PrimordialCode/~4/TaUQCiF7unk" height="1" width="1"/&gt;&lt;img src="http://feeds.feedburner.com/~r/GuardiansHome/~4/dM8RBKg-awE" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/GuardiansHome/~3/dM8RBKg-awE/configure-webmatrix-iis-express-wp7-windows7</link><author>Guardian</author><comments>http://www.primordialcode.com/blog/post/configure-webmatrix-iis-express-wp7-windows7#feedback</comments><guid isPermaLink="false">http://www.primordialcode.com/blog/post/configure-webmatrix-iis-express-wp7-windows7</guid><pubDate>Tue, 07 Feb 2012 17:15:34 GMT</pubDate><category>IIS Express</category><category>WebMatrix</category><category>WP7</category><category>Android</category><category>IPhone</category><feedburner:origLink>http://www.primordialcode.com/blog/post/configure-webmatrix-iis-express-wp7-windows7</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/PrimordialCode/~3/TaUQCiF7unk/configure-webmatrix-iis-express-wp7-windows7</feedburner:origLink></item><item><title>Windows 7 ATIKMPAG.SYS BSOD Solved (in my case)</title><description>&lt;p&gt;After having updated the drivers for my graphic card to the latest version - Catalyst 10.12 as I write this post - taken directly from the ATI website, I started to experiment some Blue Screen Of Death (BSOD) at the startup of the OS.&lt;/p&gt;  &lt;p&gt;More specifically it all was happening when the Catalyst CCC was about to be fully loaded.&lt;/p&gt;  &lt;p&gt;The error message reported by the system was something like: “atikmpag.sys has stopped responding”, followed by the memory dump.&lt;/p&gt;  &lt;p&gt;I tried some solutions found on the internet but nothing worked: I kept having the BSOD at the startup; I tried reinstalling the drivers but neither that has worked, I even tried some old versions of the drivers with no luck.&lt;/p&gt;  &lt;p&gt;I was however able to startup the machine in recovery mode, so I started looking for some files left behind by the Uninstall manager: in my private profile directory I found a file that was storing all the drivers settings and customization that were made during the previous months. That file (called Profiles.xml) was not removed during the uninstall process, looking into that I’ve found some settings that turned to be the cause of my troubles with the new drivers.&lt;/p&gt;  &lt;p&gt;To solve this issue just delete the “Profiles.xml” you can find in the user profile directory: ‘C:\Users\YOURUSERNAME\AppData\Local\ATI\ACE’; at the next restart this file will be recreated by the system with the default settings.&lt;/p&gt;  &lt;p&gt;Maybe in the past I installed some gaming profile that caused some problems or tried some ‘experimental’ configuration to improve performances that was causing troubles, I don’t really know and, actually, I don’t really care &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-openmouthedsmile" alt="Open-mouthed smile" src="http://www.primordialcode.com/UserFiles/Guardian/wlEmoticon-openmouthedsmile_2_11.png" /&gt;, but resetting it to the default values solved the problem for me avoiding a complete OS installation from scratch.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=YLHWHw8WgHM:OYIjaH8NQkI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=YLHWHw8WgHM:OYIjaH8NQkI:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=YLHWHw8WgHM:OYIjaH8NQkI:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=YLHWHw8WgHM:OYIjaH8NQkI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=YLHWHw8WgHM:OYIjaH8NQkI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=YLHWHw8WgHM:OYIjaH8NQkI:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=YLHWHw8WgHM:OYIjaH8NQkI:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=YLHWHw8WgHM:OYIjaH8NQkI:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=YLHWHw8WgHM:OYIjaH8NQkI:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/PrimordialCode/~4/YLHWHw8WgHM" height="1" width="1"/&gt;&lt;img src="http://feeds.feedburner.com/~r/GuardiansHome/~4/q0_pBeG0qRQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/GuardiansHome/~3/q0_pBeG0qRQ/windows-7-atikmpag.sys-bsod-solved-in-my-case</link><author>Guardian</author><comments>http://www.primordialcode.com/blog/post/windows-7-atikmpag.sys-bsod-solved-in-my-case#feedback</comments><guid isPermaLink="false">http://www.primordialcode.com/blog/post/windows-7-atikmpag.sys-bsod-solved-in-my-case</guid><pubDate>Thu, 02 Feb 2012 17:01:09 GMT</pubDate><category>ATI</category><category>BSOD</category><category>ATIKMPAG.SYS</category><feedburner:origLink>http://www.primordialcode.com/blog/post/windows-7-atikmpag.sys-bsod-solved-in-my-case</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/PrimordialCode/~3/YLHWHw8WgHM/windows-7-atikmpag.sys-bsod-solved-in-my-case</feedburner:origLink></item><item><title>HP ProLiant MicroServer, Windows 7 or Vista installation issues</title><description>&lt;p&gt;Stating at what HP says installing Windows Vista or Windows 7 on an HP ProLiant MicroServer (in my case the old N36L model) is not supported. This doesn’t mean it isn’t doable.&lt;/p&gt;  &lt;p&gt;All you need are the correct drivers to start the setup properly, I had an old license of Windows Vista (32 bit...ouch!) I wasn’t using anymore, so I’ve decided to install it over this piece of hardware to do some testing at my home. &lt;/p&gt;  &lt;p&gt;First problem I faced was the missing of a driver for the RAID controller (yes I set it up to use RAID 1 through the BIOS settings); once I figured out it has an AMD SATA/RAID Controller on board I started looking around for some drivers, the following package worked for me:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.primordialcode.com/userfiles/guardian/sp48266.zip"&gt;AMD SATA/RAID AHCI Controller Driver (VERSION: 3.2.1548.37 REV: G)&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Just unzip it to a folder on your USB flash drive and extract the content of the ‘exe’ file (do not run or install it), you can do it using lots of free utilities out there (WinRar, just to name one).&lt;/p&gt;  &lt;p&gt;During the setup you will need to chose on which driver install Windows, if you don’t see any drive available (as it was in my case, having built a RAID array and a logical disk), you will need to fed the setup with the correct raid controller drivers. The drivers are located in the following path inside the previously extracted directory: \sp48266\RAID7xx. There will be x86 or x64 versions of the driver, chose the one that match your OR.&lt;/p&gt;  &lt;p&gt;At this point the setup will go on and everything will be installed correctly. &lt;/p&gt;  &lt;p&gt;Next step is to use ‘Windows Update’ to finish off the installation (protect the system, keep everything updated, install eventually missing drivers and so on...), but wait...we have no valid driver for the Network Card...sob &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-openmouthedsmile" alt="Open-mouthed smile" src="http://www.primordialcode.com/UserFiles/Guardian/wlEmoticon-openmouthedsmile_2_10.png" /&gt;; once again let’s look for some information and drivers.&lt;/p&gt;  &lt;p&gt;The actual network card happens to be identified like: ‘HP NC107i PCIe Gigabit Server Adapter’ and it’s made by Broadcom, looking around a bit I was able to find&amp;#160; a list of standard drivers from the Broadcom website:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.broadcom.com/support/ethernet_nic/netxtreme_server.php"&gt;NetXtreme I Server&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Pick the ones that correspond to your OS and:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Extract the content in a folder or USB drive. &lt;/li&gt;    &lt;li&gt;Open up the Control Panel and go to the device management, highlight the missing network card, right click on it and choose update drivers. &lt;/li&gt;    &lt;li&gt;Navigate to the directory where you previously extracted the drivers and install them. &lt;/li&gt;    &lt;li&gt;Reboot the system (this is required for the drivers to be able to work). &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Forcing these drivers in my case it made the things work; now I’m able to browse my network and install updates.&lt;/p&gt;  &lt;p&gt;Some information about the hardware you can find inside a ProLiant MicroServer were taken out from the HP product sheet and the ‘support and drivers’ pages at the following url:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://h20000.www2.hp.com/bizsupport/TechSupport/ProductList.jsp?lang=en&amp;amp;cc=us&amp;amp;taskId=135&amp;amp;prodTypeId=15351&amp;amp;prodSeriesId=4248009"&gt;http://h20000.www2.hp.com/bizsupport/TechSupport/ProductList.jsp?lang=en&amp;amp;cc=us&amp;amp;taskId=135&amp;amp;prodTypeId=15351&amp;amp;prodSeriesId=4248009&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Maybe this post can help someone that is having my same issues.&lt;/p&gt;&lt;h2&gt;Related Content&lt;/h2&gt;&lt;ul&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/build-windows-8"&gt;Build: Windows 8&lt;/a&gt; (9/14/2011)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/winforms-improving-rendering-performances-backgroundimage-backgroundimagelayout"&gt;Winforms: improving rendering performances with BackgroundImage and BackgroundImageLayout&lt;/a&gt; (6/30/2010)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/a-windows-live-essentials-suite-beta-is-out.hot-to-workaround-the-no-internet-connection-setup-problem"&gt;A Windows Live Essentials Suite Beta is out...hot to workaround the ‘no internet connection’ setup problem&lt;/a&gt; (8/18/2010)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/a-windows-live-essentials-suite-beta-is-out-hot-to-workaround-the-no-internet-connection-setup-problem"&gt;A Windows Live Essentials Suite Beta is out...how to workaround the ‘no internet connection’ setup problem&lt;/a&gt; (8/18/2010)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/dexter-dynamic-pages-windows-live-writer-support"&gt;Dexter is growing: Dynamic Pages and better Windows Live Writer support&lt;/a&gt; (6/2/2010)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="/Blog/Related/hp-proliant-microserver-windows-7-or-vista-installation-issues"&gt;&lt;strong&gt;More related document (6)&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=pCfL17piaB8:5a4rhZ2u99Q:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=pCfL17piaB8:5a4rhZ2u99Q:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=pCfL17piaB8:5a4rhZ2u99Q:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=pCfL17piaB8:5a4rhZ2u99Q:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=pCfL17piaB8:5a4rhZ2u99Q:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=pCfL17piaB8:5a4rhZ2u99Q:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=pCfL17piaB8:5a4rhZ2u99Q:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=pCfL17piaB8:5a4rhZ2u99Q:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=pCfL17piaB8:5a4rhZ2u99Q:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/PrimordialCode/~4/pCfL17piaB8" height="1" width="1"/&gt;&lt;img src="http://feeds.feedburner.com/~r/GuardiansHome/~4/OCPX5wiTA3M" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/GuardiansHome/~3/OCPX5wiTA3M/hp-proliant-microserver-windows-7-or-vista-installation-issues</link><author>Guardian</author><comments>http://www.primordialcode.com/blog/post/hp-proliant-microserver-windows-7-or-vista-installation-issues#feedback</comments><guid isPermaLink="false">http://www.primordialcode.com/blog/post/hp-proliant-microserver-windows-7-or-vista-installation-issues</guid><pubDate>Tue, 13 Dec 2011 20:28:36 GMT</pubDate><category>HP</category><category>ProLiant</category><category>Windows 7</category><category>Windows Vista</category><feedburner:origLink>http://www.primordialcode.com/blog/post/hp-proliant-microserver-windows-7-or-vista-installation-issues</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/PrimordialCode/~3/pCfL17piaB8/hp-proliant-microserver-windows-7-or-vista-installation-issues</feedburner:origLink></item><item><title>Creating a ‘Windows Installation’ bootable USB drive</title><description>&lt;p&gt;Recently I was in need to setup some new hardware and I’ve found myself doing this procedure over and over (because I am a cheap b*****d and I only own few USB pen drives &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-openmouthedsmile" alt="Open-mouthed smile" src="http://www.primordialcode.com/UserFiles/Guardian/wlEmoticon-openmouthedsmile_2_9.png" /&gt;) again. So even if there are plenty of posts out there offering more or less the same content, I’ll write it down here as a reminder to myself.&lt;/p&gt;  &lt;p&gt;Consider you can use this very same procedure to create a bootable USB flash drive to install any Microsoft Windows OS (from Vista to 2008 Server R2).&lt;/p&gt;  &lt;h3&gt;Prepare and Format the drive&lt;/h3&gt;  &lt;p&gt;You can do these first steps in several way, I prefer to use the &lt;strong&gt;diskpart&lt;/strong&gt; command line utility; BE CAREFUL HERE! If you do something wrong you may easily wipeout you disks!&amp;#160; &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Open a command prompt as administrator (Right click on Start &amp;gt; All Programs &amp;gt; Accessories &amp;gt; Command Prompt and select “Run as administrator”)      &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;type the following commands into the Command Prompt Window:      &lt;br /&gt;      &lt;br /&gt;&amp;#160; diskpart       &lt;br /&gt;      &lt;br /&gt;&amp;#160; list disk       &lt;br /&gt;      &lt;br /&gt;This will bring up a list of all your physical drives installed; look for your USB drive and take note of the number; if you have multiple USB drives attached I suggest you to disconnect them all but the one you want to use: the only way to identify the drive is looking at the drive’s size in this step, having multiple USB drives with the same capacity is not good!       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Format the drive by typing the following commands into the same window. Replace “X” with the number of your disk.      &lt;br /&gt;      &lt;br /&gt;select disk X      &lt;br /&gt;      &lt;br /&gt;clean       &lt;br /&gt;      &lt;br /&gt;create partition primary      &lt;br /&gt;       &lt;br /&gt;select partition 1       &lt;br /&gt;      &lt;br /&gt;active       &lt;br /&gt;      &lt;br /&gt;format fs=NTFS       &lt;br /&gt;      &lt;br /&gt;assign       &lt;br /&gt;      &lt;br /&gt;exit       &lt;br /&gt;      &lt;br /&gt;At this stage we have a clean formatted USB with an active partition ready to be made bootable. Some guides will tell you to format the pen drive using FAT32, I always prefer to use NTFS especially to create bootable winpe drives to use the imagex.exe utility to clone systems, in this scenario we can easily break through the FAT32 file size limit.&lt;/li&gt; &lt;/ol&gt;  &lt;h3&gt;Make the drive bootable&lt;/h3&gt;  &lt;p&gt;To make the drive bootable we will use the &lt;strong&gt;bootsect&lt;/strong&gt; utility that comes along with any Microsoft Windows OS:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Insert your OS DVD.     &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Change directory to X:\boot (where X is your dvd drive).     &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Type the following instruction to make the drive bootable (now ‘X’ is your pen drive).     &lt;br /&gt;      &lt;br /&gt;bootsect /nt60 X:      &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Close the Command Prompt Window.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The last step is copy all your installation files from the DVD (or ISO) to your newly created bootable USB flash drive.&lt;/p&gt;  &lt;p&gt;If you do not want to do everything by hand, there’s a tool from Microsoft you can use to do the very same work: &lt;a href="http://www.microsoftstore.com/store/msstore/html/pbPage.Help_Win7_usbdvd_dwnTool"&gt;Windows 7 USB/DVD download tool&lt;/a&gt;.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=2UnXmAyMLLk:TkdR34G4lQY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=2UnXmAyMLLk:TkdR34G4lQY:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=2UnXmAyMLLk:TkdR34G4lQY:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=2UnXmAyMLLk:TkdR34G4lQY:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=2UnXmAyMLLk:TkdR34G4lQY:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=2UnXmAyMLLk:TkdR34G4lQY:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=2UnXmAyMLLk:TkdR34G4lQY:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=2UnXmAyMLLk:TkdR34G4lQY:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=2UnXmAyMLLk:TkdR34G4lQY:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/PrimordialCode/~4/2UnXmAyMLLk" height="1" width="1"/&gt;&lt;img src="http://feeds.feedburner.com/~r/GuardiansHome/~4/-3SE3dW9lDA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/GuardiansHome/~3/-3SE3dW9lDA/creating-a-windows-installation-bootable-usb-drive</link><author>Guardian</author><comments>http://www.primordialcode.com/blog/post/creating-a-windows-installation-bootable-usb-drive#feedback</comments><guid isPermaLink="false">http://www.primordialcode.com/blog/post/creating-a-windows-installation-bootable-usb-drive</guid><pubDate>Tue, 13 Dec 2011 01:19:44 GMT</pubDate><category>Usb</category><category>Boot</category><feedburner:origLink>http://www.primordialcode.com/blog/post/creating-a-windows-installation-bootable-usb-drive</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/PrimordialCode/~3/2UnXmAyMLLk/creating-a-windows-installation-bootable-usb-drive</feedburner:origLink></item><item><title>Build: Windows 8</title><description>&lt;p&gt;I bet almost all the developers followed the ‘build’ keynote Yesterday, we had some big news (nothing too much scary, thankfully) and we saw Windows running on a bunch of new devices (I honestly can’t wait to put my hands on them) that will hit the market sooner or later in the future.&lt;/p&gt;  &lt;p&gt;On the Dev side, I’m very excited for what we saw: new potentials, some big improvements and a potentially rewritten and optimized infrastructure over which your apps will run on. I loved the metro style UI on WP7 and this ‘bigger brother’ seems very good to me. And yes the ‘pro’ will have their usual desktop view too (with productivity improvements on that side too).&lt;/p&gt;  &lt;p&gt;On the consumer and business side, timing here is quite important: when this new beast will be released to the market ? will it be too late to compete against its ‘enemies’ ? when the new devices will be available ? and another one... pricing ? will it get a good welcome from the customers? we can go on and on and on... &lt;/p&gt;  &lt;p&gt;Windows 8 should focus its target on the new devices and new installations, because hoping that a big part of the pre-existing windows installed machine will be updated to windows 8 in the close future is just...well...chose your word here!.&lt;/p&gt;  &lt;p&gt;Here in Italy before updating any windows version to the new one the usual policy is to ‘wait for the SP1’, people is just scared of changes (and of course the ‘money factor’ plays its main role too, which will stops many businesses to early adopt it).&lt;/p&gt;  &lt;p&gt;While we wait and think about all of this, we (devs) can happily put our hands on a Developer Preview of Windows 8, head up to MSDN for more info or just follow these links:&lt;/p&gt;  &lt;p&gt;Windows Developer Preview: &lt;a href="http://msdn.microsoft.com/en-us/windows/apps/br229516"&gt;http://msdn.microsoft.com/en-us/windows/apps/br229516&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Build Keynote &amp;amp; sessions info: &lt;a href="http://www.microsoft.com/presspass/events/build/"&gt;http://www.microsoft.com/presspass/events/build/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Build sessions will be available through Channel 9: &lt;a href="http://channel9.msdn.com/Events/BUILD/BUILD2011?sort=sequential&amp;amp;direction=desc&amp;amp;term"&gt;http://channel9.msdn.com/Events/BUILD/BUILD2011?sort=sequential&amp;amp;direction=desc&amp;amp;term&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Time to have some fun (again)!&lt;/p&gt;&lt;h2&gt;Related Content&lt;/h2&gt;&lt;ul&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/winforms-improving-rendering-performances-backgroundimage-backgroundimagelayout"&gt;Winforms: improving rendering performances with BackgroundImage and BackgroundImageLayout&lt;/a&gt; (6/30/2010)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/a-windows-live-essentials-suite-beta-is-out.hot-to-workaround-the-no-internet-connection-setup-problem"&gt;A Windows Live Essentials Suite Beta is out...hot to workaround the ‘no internet connection’ setup problem&lt;/a&gt; (8/18/2010)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/a-windows-live-essentials-suite-beta-is-out-hot-to-workaround-the-no-internet-connection-setup-problem"&gt;A Windows Live Essentials Suite Beta is out...how to workaround the ‘no internet connection’ setup problem&lt;/a&gt; (8/18/2010)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/dexter-dynamic-pages-windows-live-writer-support"&gt;Dexter is growing: Dynamic Pages and better Windows Live Writer support&lt;/a&gt; (6/2/2010)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/hp-proliant-microserver-windows-7-or-vista-installation-issues"&gt;HP ProLiant MicroServer, Windows 7 or Vista installation issues&lt;/a&gt; (12/13/2011)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="/Blog/Related/build-windows-8"&gt;&lt;strong&gt;More related document (6)&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=T7whey93OVg:Ic4YRpowmLw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=T7whey93OVg:Ic4YRpowmLw:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=T7whey93OVg:Ic4YRpowmLw:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=T7whey93OVg:Ic4YRpowmLw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=T7whey93OVg:Ic4YRpowmLw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=T7whey93OVg:Ic4YRpowmLw:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=T7whey93OVg:Ic4YRpowmLw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=T7whey93OVg:Ic4YRpowmLw:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=T7whey93OVg:Ic4YRpowmLw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/PrimordialCode/~4/T7whey93OVg" height="1" width="1"/&gt;&lt;img src="http://feeds.feedburner.com/~r/GuardiansHome/~4/JaSlvgtznQU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/GuardiansHome/~3/JaSlvgtznQU/build-windows-8</link><author>Guardian</author><comments>http://www.primordialcode.com/blog/post/build-windows-8#feedback</comments><guid isPermaLink="false">http://www.primordialcode.com/blog/post/build-windows-8</guid><pubDate>Wed, 14 Sep 2011 17:13:25 GMT</pubDate><category>Windows 8</category><category>Build</category><feedburner:origLink>http://www.primordialcode.com/blog/post/build-windows-8</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/PrimordialCode/~3/T7whey93OVg/build-windows-8</feedburner:origLink></item><item><title>NHibernate.Envers - Customize the Revision Entity</title><description>&lt;p&gt;Sometimes the basic information provided by the default revision entity we have in &lt;a href="http://nhforge.org/"&gt;NHibernate&lt;/a&gt;.Envers are not enough, when we need to extend those information and provide additional data we have the option to use a customized version of the Revision Entity class.&lt;/p&gt;  &lt;p&gt;The default revision entity is defined like this:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:b80f4206-297b-417c-9f8b-8bea7f86978c" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: csharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: true; "&gt;[Serializable]
public class DefaultRevisionEntity
{
	[RevisionNumber]
	public virtual int Id { get; set; }

	[RevisionTimestamp]
	public virtual DateTime RevisionDate { get; set; }

	public override bool Equals(object obj)
	{
		if (this == obj) return true;
		var revisionEntity = obj as DefaultRevisionEntity;
		if (revisionEntity == null) return false;

		var that = revisionEntity;

		if (Id != that.Id) return false;
		return RevisionDate == that.RevisionDate;
	}

	public override int GetHashCode()
	{
		var result = Id;
		result = 31 * result + (int)(((ulong)RevisionDate.Ticks) ^ (((ulong)RevisionDate.Ticks) &amp;gt;&amp;gt; 32));
		return result;
	}
}&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;You can notice two properties that defines the information that a Revision Entity class MUST have, they are also marked by two configuration attributes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;[RevisionNumber] - states which property will represent the revision number of the version&lt;/li&gt;

  &lt;li&gt;[RevisionTimestamp] - states the timestamp of the version&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every custom Revision Entity class MUST have these two kind of properties, once again we will use the fluent by code configuration so we will not need to decorate our classes with attributes (I’ll show how to configure NHibernate.Envers using attributes in another post).&lt;/p&gt;

&lt;p&gt;Our custom Revision Entity class for this example will be:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:45d82845-8a30-4d84-870e-d04e3a103058" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: csharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: true; "&gt;//[RevisionEntity]
public class REVINFO
{
	//[RevisionNumber]
	public virtual long Id { get; set; }

	//[RevisionTimestamp]
	public virtual DateTime CustomTimestamp { get; set; }

	public virtual string Data { get; set; }

	public override bool Equals(object obj)
	{
		var casted = obj as REVINFO;
		if (casted == null)
			return false;
		return (Id == casted.Id &amp;amp;&amp;amp;
				CustomTimestamp.Equals(casted.CustomTimestamp) &amp;amp;&amp;amp;
				Data.Equals(casted.Data));
	}

	public override int GetHashCode()
	{
		return Id.GetHashCode() ^ CustomTimestamp.GetHashCode() ^ Data.GetHashCode();
	}
}&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;As you can see we have the two basic properties plus an additional Data field that will represent our custom data added to each revision tracked.&lt;/p&gt;

&lt;p&gt;To be able to fill these data we need to implement a particular type of interface: an &lt;strong&gt;IRevisionListener&lt;/strong&gt;. This interface expose only a single member function - void NewRevision(object) - and it’s called every time a new revision object is generated. The demo code is:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:c30908fa-da7a-42a0-96c1-f97b5e0ade79" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: csharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: true; "&gt;public class RevInfoListener : IRevisionListener
{
	public static string Data = &amp;quot;test data&amp;quot;;

	public void NewRevision(object revisionEntity)
	{
		((REVINFO)revisionEntity).Data = Data;
	}
}&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;The last step is to change the configuration to ‘inject’ our custom Revision Entity class and Listener; in my test project I do it with the following code:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:d27bdda2-ba09-4c44-8856-2b6c71a5dc9d" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: csharp; gutter: true; first-line: 1; tab-size: 4;  toolbar: true; "&gt;public class NHinitCustomRevInfo : NHibernateInitializer
{
	protected override System.Collections.Generic.IEnumerable&amp;lt;System.Type&amp;gt; GetDomainEntities()
	{
		// I am using ConfORM to emit the mappings, so we add it to the mapped classes.
		return base.GetDomainEntities().Union(new[] { typeof(REVINFO) });
	}
	
	protected override void ConfOrmMapping(ConfOrm.ObjectRelationalMapper orm, ConfOrm.NH.Mapper mapper)
	{
		// I have to provide a mapping for a custom RevInfo class...NHibernate must know how to handle these objects
		orm.TablePerClass&amp;lt;REVINFO&amp;gt;();
		
		orm.TablePerClass&amp;lt;Person&amp;gt;();
		orm.TablePerClass&amp;lt;Game&amp;gt;();
	}

	public void InitializeAudit()
	{
		// initialize the NHibernate.Envers fluent configuration object
		var enversConf = new NHibernate.Envers.Configuration.Fluent.FluentConfiguration();

		// I prefer to not use attributes to configure the custom revision entity
		enversConf.SetRevisionEntity&amp;lt;REVINFO&amp;gt;(e =&amp;gt; e.Id, e =&amp;gt; e.CustomTimestamp, typeof(RevInfoListener));
		
		// the RevInfo class must not be in the auditing list
		enversConf.Audit(GetDomainEntities().Where(e =&amp;gt; !typeof(REVINFO).IsAssignableFrom(e)));

		// to inspect the metadata
		//var mets = enversConf.CreateMetaData(Configure);

		// Configure.Properties.Add(&amp;quot;nhibernate.envers.audit_table_prefix&amp;quot;, string.Empty); // default
		Configure.Properties.Add(&amp;quot;nhibernate.envers.audit_table_suffix&amp;quot;, &amp;quot;_REV&amp;quot;); // default _AUD
		// Configure.Properties.Add(&amp;quot;nhibernate.envers.revision_field_name&amp;quot;, &amp;quot;REV&amp;quot;); // default
		// Configure.Properties.Add(&amp;quot;nhibernate.envers.revision_type_field_name&amp;quot;, &amp;quot;REVTYPE&amp;quot;); // default

		Configure.IntegrateWithEnvers(enversConf);
	}
}&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;I am using &lt;a href="http://code.google.com/p/codeconform/" target="_blank"&gt;ConfORM&lt;/a&gt; and my mapping engine, so part of the configuration is related to how it’s used to generate the mappings, but the concepts are valid for any other mapping tools you use; Let’s go through it:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Line 6: we add the REVINFO class to my mapped domain, ConfORM need to be aware of it.&lt;/li&gt;

  &lt;li&gt;Line 12: we tell ConfORM how to map the class.&lt;/li&gt;

  &lt;li&gt;Line 21: we initialize the NHibernate.Envers fluent configuration engine.&lt;/li&gt;

  &lt;li&gt;Line 24: this is the crucial point, we specify our custom Revision Entity class type, we tell Envers which functions to use to fill in the Revision incremental number and the Revision Timestamp; plus we pass in the type of the IRevisionListener implementation if we want to specify additional data in the custom revision entity class.&lt;/li&gt;

  &lt;li&gt;Line 27: we tell to NHibernate.Envers which classes we want to track (be careful to exclude the REVINFO class from the tracked ones here).&lt;/li&gt;

  &lt;li&gt;Line 37: we add NHibernate.Envers to the standard NHibernate configuration.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If we create a simple test and execute it we can inspect the schema of the generated database to see the custom revision entity in place:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.primordialcode.com/UserFiles/Guardian/NHibernateEnversSampleSchemaCustomRevEnt_2.jpg"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 4px 10px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Database Schema with Custom Revision Entity" border="0" alt="Database Schema with Custom Revision Entity" src="http://www.primordialcode.com/UserFiles/Guardian/NHibernateEnversSampleSchemaCustomRevEnt_thumb.jpg" width="554" height="467" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Figure 1 - Database Schema with Custom Revision Entity&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That’s all for this post, next time we’ll see how to query for the extended revision entity properties we just added.&lt;/p&gt;&lt;h2&gt;Related Content&lt;/h2&gt;&lt;ul&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/nhibernate-envers-quick-introduction"&gt;NHibernate.Envers - a quick introduction&lt;/a&gt; (6/7/2011)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/nhibernate-envers-querying-part-1"&gt;NHibernate.Envers - Querying - part 1&lt;/a&gt; (6/10/2011)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/nhibernate-envers-querying-part-2"&gt;NHibernate.Envers - Querying - part 2&lt;/a&gt; (7/13/2011)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/silverlight-wcf-fixing-custom-wcf-proxy-generator"&gt;Silverlight / WCF: fixing the Custom WCF Proxy Generator&lt;/a&gt; (12/16/2009)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/silverlight-wcf-writing-custom-wcf-proxy-generator-support-validation"&gt;Silverlight / WCF : Writing your own Custom WCF Proxy Generator to support validation&lt;/a&gt; (12/9/2009)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="/Blog/Related/nhibernate-envers-customize-revision-entity"&gt;&lt;strong&gt;More related document (4)&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=8vSD5cvoUOc:60q182ZZD60:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=8vSD5cvoUOc:60q182ZZD60:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=8vSD5cvoUOc:60q182ZZD60:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=8vSD5cvoUOc:60q182ZZD60:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=8vSD5cvoUOc:60q182ZZD60:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=8vSD5cvoUOc:60q182ZZD60:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=8vSD5cvoUOc:60q182ZZD60:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=8vSD5cvoUOc:60q182ZZD60:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=8vSD5cvoUOc:60q182ZZD60:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/PrimordialCode/~4/8vSD5cvoUOc" height="1" width="1"/&gt;&lt;img src="http://feeds.feedburner.com/~r/GuardiansHome/~4/2re2kk6-vF4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/GuardiansHome/~3/2re2kk6-vF4/nhibernate-envers-customize-revision-entity</link><author>Guardian</author><comments>http://www.primordialcode.com/blog/post/nhibernate-envers-customize-revision-entity#feedback</comments><guid isPermaLink="false">http://www.primordialcode.com/blog/post/nhibernate-envers-customize-revision-entity</guid><pubDate>Fri, 05 Aug 2011 21:10:17 GMT</pubDate><category>Nhibernate.Envers</category><category>Custom</category><feedburner:origLink>http://www.primordialcode.com/blog/post/nhibernate-envers-customize-revision-entity</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/PrimordialCode/~3/8vSD5cvoUOc/nhibernate-envers-customize-revision-entity</feedburner:origLink></item><item><title>Sql Server - Scramble / Mask database production data</title><description>&lt;p&gt;Sometimes you might need to test your product using some ‘production’ data to better simulate what users do with your software.&lt;/p&gt;  &lt;p&gt;There are situations in which having only your test database, with your own (well formed) test data is not enough: just think of a continuously growing database with frequent schema changes...you might likely have inconsistencies between the data as you upgrade it or unpredicted behaviors.&lt;/p&gt;  &lt;p&gt;If you want use a copy or a snapshot of a production database for test purposes, you should at least try to hide the sensitive data away (in a way that is really hard or impossible for your development team or anyone else that have access to the database to reconstruct them).&lt;/p&gt;  &lt;p&gt;As you can imagine the task here can be extremely difficult to accomplish and there might be some tools out there that can help you doing this job.&lt;/p&gt;  &lt;p&gt;If you do not want to invest in them a quick and dirty solution (it took me more or less 15 minutes to put it all together, and I’m not a SQL expert) can be writing some SQL scripts to modify what you consider to be your most sensitive data, leaving everything else intact. It doesn’t guarantee that all the sensitive data are hidden/changed because it relies on the code you write.&lt;/p&gt;  &lt;p&gt;The typical scenario is to modify the names and telephone numbers of some personal data records, but you can apply this technique to anything you want.&lt;/p&gt;  &lt;p&gt;Fist we need some functions to create test data, here you can use anything you want but I prefer something that generates data based on a prefix I can pass in; you can easily create functions that generate completely random data, but it will be hard to talk to your team and say something like: “ehi...check the person named ‘XWggTRDnnns’!”, a simple string concatenation does the job here.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:4cec6735-6ca1-4f69-be54-3a8eb4d4db45" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: sql; gutter: false; first-line: 1; tab-size: 4;  toolbar: true; "&gt;--concatenates a generic string and an incremental number
CREATE FUNCTION fn_GenerateText(@prefix varchar(255), @incr int)
RETURNS varchar(255)
AS
BEGIN
return @prefix + CONVERT(varchar(100),@incr)
END
GO&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;Next we need to scan all our data tables and update the data we find there, here I decided to use a cursor (it’s not efficient but you can handle any type of key in this way, from guids to strings), so the idea is:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;read each line of the table&lt;/li&gt;

  &lt;li&gt;generate some test data for each of the sensitive columns with text like: ‘name0’, ‘surname0’, etc... the number will be incremented for each line&lt;/li&gt;

  &lt;li&gt;update the data row with the given data for each of the columns you need to modify&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:7ed732a9-ab35-45e5-a545-0bcab4f9926c" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: sql; gutter: false; first-line: 1; tab-size: 4;  toolbar: true; "&gt;-- a variable we use to generate incremental numbers
Declare @i int
set @i = 0

-- let's use a cursor, i don't know the data type of the key column
declare @id uniqueidentifier;
Declare id_cursor CURSOR
	FOR select AP_ID from dbo.PersonalData;
open id_cursor;
fetch next from id_cursor into @id;

WHILE @@FETCH_STATUS = 0
BEGIN

update  dbo.PersonalData
set 
AP_Note = dbo.fn_GenerateText('test', @i),
AP_FiscalCode = dbo.fn_GenerateText('fc', @i), -- or use a valid fiscal code generation routine here
AP_Surname = dbo.fn_GenerateText('surname', @i),
AP_Name = dbo.fn_GenerateText('name', @i),
AP_Phone = dbo.fn_GenerateText('t', @i),
AP_CellPhone = dbo.fn_GenerateText('c', @i)
Where AP_ID = @id 

-- increment the suffix and get the new data from the cursor
set @i = @i+1;
fetch next from id_cursor into @id;
END
CLOSE id_cursor;
DEALLOCATE id_cursor;
GO&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;
&lt;/p&gt;

&lt;p&gt;In the end we just cleanup the database from every support function we created:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:d5de8880-8b28-4e97-a879-5d5843b2a2a3" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: sql; gutter: false; first-line: 1; tab-size: 4;  toolbar: true; "&gt;DROP FUNCTION dbo.fn_GenerateText
GO&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;As you can see this is a very quick solution and you will have to write some SQL code and manage the relations by yourself if needed, nonetheless once you have your scripts in place it’s a quite easy solution to use and maintain.&lt;/p&gt;&lt;h2&gt;Related Content&lt;/h2&gt;&lt;ul&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/nhibernate-prepare_sql-considerations-mapping-long-string-fields"&gt;NHibernate - prepare_sql and some considerations on mapping very long string fields&lt;/a&gt; (8/26/2010)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/install-sql-server-express-with-your-application"&gt;Install SQL Server (Express) with your Application&lt;/a&gt; (1/29/2009)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="/Blog/Related/sql-server-scramble-mask-database-production-data"&gt;&lt;strong&gt;More related document (1)&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=INlMDCOjIrg:b_Q2OYcy3-c:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=INlMDCOjIrg:b_Q2OYcy3-c:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=INlMDCOjIrg:b_Q2OYcy3-c:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=INlMDCOjIrg:b_Q2OYcy3-c:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=INlMDCOjIrg:b_Q2OYcy3-c:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=INlMDCOjIrg:b_Q2OYcy3-c:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=INlMDCOjIrg:b_Q2OYcy3-c:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=INlMDCOjIrg:b_Q2OYcy3-c:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=INlMDCOjIrg:b_Q2OYcy3-c:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/PrimordialCode/~4/INlMDCOjIrg" height="1" width="1"/&gt;&lt;img src="http://feeds.feedburner.com/~r/GuardiansHome/~4/rXaNHVHjkN8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/GuardiansHome/~3/rXaNHVHjkN8/sql-server-scramble-mask-database-production-data</link><author>Guardian</author><comments>http://www.primordialcode.com/blog/post/sql-server-scramble-mask-database-production-data#feedback</comments><guid isPermaLink="false">http://www.primordialcode.com/blog/post/sql-server-scramble-mask-database-production-data</guid><pubDate>Wed, 27 Jul 2011 18:59:49 GMT</pubDate><category>SQL</category><category>Scramble</category><feedburner:origLink>http://www.primordialcode.com/blog/post/sql-server-scramble-mask-database-production-data</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/PrimordialCode/~3/INlMDCOjIrg/sql-server-scramble-mask-database-production-data</feedburner:origLink></item><item><title>Fetching collections with NHibernate, a mistake a I always do!</title><description>&lt;p&gt;I did it again! That’s why I’m writing this blog post...I do it almost every time and the main reason is: trying to optimize &lt;a href="http://nhforge.org/"&gt;NHibernate&lt;/a&gt; queries without thinking.&lt;/p&gt;  &lt;p&gt;As the title of the posts says the problem here is related to fetching the data of different collections attached to a single entity. To show you up the problem let’s first see the test domain, it is very simple:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:bcc9a39b-2139-4ed7-91b2-1835d47599d5" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: csharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: true; "&gt;public class Post : Entity&amp;lt;int&amp;gt;
{
	protected Post()
	{
	}

	public Post(string slug)
	{
		Slug = slug;
		Categories = new List&amp;lt;Category&amp;gt;();
		Tags = new List&amp;lt;Tag&amp;gt;();
	}

	public string Slug { get; set; }

	public IList&amp;lt;Category&amp;gt; Categories { get; set; }

	public IList&amp;lt;Tag&amp;gt; Tags { get; set; }	
}

public class Category : Entity&amp;lt;int&amp;gt;
{
	public string Name { get; set; }
}

public class Tag : Entity&amp;lt;int&amp;gt;
{
	public string Name { get; set; }
}&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;I generated some test data consisting of a single post which has 2 categories and 2 tags associated to it.&lt;/p&gt;

&lt;p&gt;We want to query the Post object together with all it’s data, the first thing we can do is this:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:c82a353f-2fb5-4961-ac59-39fb08c75e36" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: csharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: true; "&gt;[Test]
public void NoFetch_Success()
{
	using (ISession s = _nh.SessionFactory.OpenSession())
	{
		// look for a non existing revision
		using (var tx = s.BeginTransaction())
		{
			var p = s.CreateQuery(&amp;quot;from Post p where p.Slug = :slug&amp;quot;)
				.SetParameter(&amp;quot;slug&amp;quot;, &amp;quot;Slug&amp;quot;)
				.UniqueResult&amp;lt;Post&amp;gt;();

			tx.Commit();

			Assert.IsNotNull(p);
			Assert.AreEqual(2, p.Categories.Count);
			Assert.AreEqual(2, p.Tags.Count);
		}
	}
}&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;Straightforward and simple; this thing produces 3 different queries, one for each kind of object:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:00903a7a-e0ed-4456-bcf7-862d1a5e2aa8" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: sql; gutter: false; first-line: 1; tab-size: 4;  toolbar: true; "&gt;select post0_.Id as Id0_, post0_.Slug as Slug0_ from Post post0_ where post0_.Slug=@p0;@p0 = 'Slug' [Type: String (4000)]

SELECT categories0_.PostId as PostId1_, categories0_.Id as Id1_, categories0_.Id as Id1_0_, categories0_.Name as Name1_0_ FROM Category categories0_ WHERE categories0_.PostId=@p0;@p0 = 1 [Type: Int32 (0)]

SELECT tags0_.PostId as PostId1_, tags0_.Id as Id1_, tags0_.Id as Id2_0_, tags0_.Name as Name2_0_ FROM Tag tags0_ WHERE tags0_.PostId=@p0;@p0 = 1 [Type: Int32 (0)]
		&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;The returned data are all correct.&lt;/p&gt;

&lt;p&gt;But we really have too many queries here and we want to optimize it a bit (in order to limit/prevent the impact of the n+1 selects problem), so in my optimization berserker fury I started using fetch joins to retrieve more data in a single pass and I wrote this query:&lt;/p&gt;

&lt;pre&gt;from Post p left join fetch p.Categories left join fetch p.Tags where p.Slug = :slug&lt;/pre&gt;

&lt;p&gt;which is an absolute mistake, because it generates duplicated data; let’s see some test code:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:4e780514-eac5-4df3-bc7f-2d9396983ce4" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: csharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: true; "&gt;[Test]
public void FetchALL_Failure()
{
	using (ISession s = _nh.SessionFactory.OpenSession())
	{
		// look for a non existing revision
		using (var tx = s.BeginTransaction())
		{
			// try adding a: select distinct p 
			var p = s.CreateQuery(&amp;quot;from Post p left join fetch p.Categories left join fetch p.Tags where p.Slug = :slug&amp;quot;)
				.SetParameter(&amp;quot;slug&amp;quot;, &amp;quot;Slug&amp;quot;)
				.UniqueResult&amp;lt;Post&amp;gt;();

			tx.Commit();

			Assert.IsNotNull(p);
			Assert.AreEqual(2, p.Categories.Count); // &amp;lt;- big exception... we have 4 rows
			Assert.AreEqual(2, p.Tags.Count);
		}
	}
}&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;which produces 1 single query:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:5544f78b-7878-41db-ae0e-b88ac70d189c" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: sql; gutter: false; first-line: 1; tab-size: 4;  toolbar: true; "&gt;select post0_.Id as Id0_0_, categories1_.Id as Id1_1_, tags2_.Id as Id2_2_, post0_.Slug as Slug0_0_, categories1_.Name as Name1_1_, categories1_.PostId as PostId0__, categories1_.Id as Id0__, tags2_.Name as Name2_2_, tags2_.PostId as PostId1__, tags2_.Id as Id1__ from Post post0_ left outer join Category categories1_ on post0_.Id=categories1_.PostId left outer join Tag tags2_ on post0_.Id=tags2_.PostId where post0_.Slug=@p0;@p0 = 'Slug' [Type: String (4000)]&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;But the data are all wrong! In fact the Assert that should check for the correct numbers of categories are telling me that I have 4 rows inside that collection. I should have reminded earlier what the NHibernate documentation says about this situation:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;It is possible to create a cartesian product by join fetching more than one collection in a query, so take care in this case. Join fetching multiple collection roles is also disabled for bag mappings. Note also that the &lt;tt&gt;fetch&lt;/tt&gt; construct may not be used in queries called using &lt;tt&gt;Enumerable()&lt;/tt&gt;. Finally, note that &lt;tt&gt;full join fetch&lt;/tt&gt; and &lt;tt&gt;right join fetch&lt;/tt&gt; are not meaningful. (Reference documentation, 13.3 Associations and joins)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Note that adding a ‘select distinct p’ will not help in this case.&lt;/p&gt;

&lt;p&gt;To fix this we need to have just one fetch join at each level of the hierarchy; we can write something like this:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:44d2dc2f-c227-4384-b6f1-5de85dc58bbb" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: csharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: true; "&gt;var p = s.CreateQuery(&amp;quot;from Post p left join fetch p.Categories where p.Slug = :slug&amp;quot;)
						.SetParameter(&amp;quot;slug&amp;quot;, &amp;quot;Slug&amp;quot;)
						.UniqueResult&amp;lt;Post&amp;gt;();&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;This code will generate 2 queries (one to get the Post and the Categories and one to get the Tags) and the test will pass:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:c7a5bcb3-7c8f-4d81-90ec-65e8733e52ed" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: sql; gutter: false; first-line: 1; tab-size: 4;  toolbar: true; "&gt;select post0_.Id as Id12_0_, categories1_.Id as Id13_1_, post0_.Slug as Slug12_0_, categories1_.Name as Name13_1_, categories1_.PostId as PostId0__, categories1_.Id as Id0__ from Post post0_ left outer join Category categories1_ on post0_.Id=categories1_.PostId where post0_.Slug=@p0;@p0 = 'Slug' [Type: String (4000)]
		
SELECT tags0_.PostId as PostId1_, tags0_.Id as Id1_, tags0_.Id as Id14_0_, tags0_.Name as Name14_0_ FROM Tag tags0_ WHERE tags0_.PostId=@p0;@p0 = 1 [Type: Int32 (0)]&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;But...wait! .UniqueResult&amp;lt;T&amp;gt;() here is smart enough to hide us a fetch join side effect; if we use .List&amp;lt;T&amp;gt;() instead we will see it clearly: the fetch introduces ‘ghosts’ in our returned resultset; the data will be a combination of Posts and Categories fields, so for any single Post object we will have ‘n’ records (one for each Category bound to the Post) and NHibernate will output ‘n’ Post entities, all of them containing the same data.&lt;/p&gt;

&lt;p&gt;The solution here is pretty simple: just add the ‘distinct’ keyword to the select statement (or use the DistinctRootEntityTransformer), this way we are telling NHibernate to give us back all the unique instances of Post objects together with their Categories, here is the code:&lt;/p&gt;

&lt;p&gt;
  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:19fe3c40-1ae7-4a6e-b379-9d5ee64a9b14" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: csharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: true; "&gt;[Test]
public void FetchSingleCollection_Distinct_Success()
{
	using (ISession s = _nh.SessionFactory.OpenSession())
	{
		// look for a non existing revision
		using (var tx = s.BeginTransaction())
		{
			var p = s.CreateQuery(&amp;quot;select distinct p from Post p left join fetch p.Categories where p.Slug = :slug&amp;quot;)
				.SetParameter(&amp;quot;slug&amp;quot;, &amp;quot;Slug&amp;quot;)
				.UniqueResult&amp;lt;Post&amp;gt;();
			tx.Commit();

			Assert.IsNotNull(p);
			Assert.AreEqual(2, p.Categories.Count);
			Assert.AreEqual(2, p.Tags.Count);
		}
	}
}&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;
&lt;/p&gt;

&lt;p&gt;If I remind it well, there’s no need to use the distinct on the queries generated using Linq to NHibernate, because the provider does it for you.&lt;/p&gt;

&lt;p&gt;As usual here’s the test project for those who want to play with it:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:fbf49488-e8fb-4ef2-b02d-7491959571f0" class="wlWriterEditableSmartContent"&gt;&lt;p&gt;&lt;div&gt;&lt;a href="http://www.primordialcode.com/UserFiles/Guardian/NHibernateTestsCollectionFetching.zip" target="_self"&gt;NHibernateTestsCollectionFetching.zip&lt;/a&gt;&lt;/div&gt;&lt;/p&gt;&lt;/div&gt;

&lt;p&gt;I am hoping, now that I’ve wrote it down, to not make the same mistake again &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-openmouthedsmile" alt="Open-mouthed smile" src="http://www.primordialcode.com/UserFiles/Guardian/wlEmoticon-openmouthedsmile_2_8.png" /&gt;...&lt;/p&gt;&lt;h2&gt;Related Content&lt;/h2&gt;&lt;ul&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/nhibernate-eager-fetch-order-strange-behavior-icriteria"&gt;NHibernate - Eager Fetch, Order By and a strange behavior with ICriteria&lt;/a&gt; (7/13/2010)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/breaking-news-european-nhibernate-day-officially-announced"&gt;Breaking news: the First European NHibernate Day had been officially announced&lt;/a&gt; (5/20/2010)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/nhibernate-impressions-conform"&gt;NHibernate - First impressions on ConfORM&lt;/a&gt; (9/24/2010)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/nhibernate-customize-linq-provider-user-defined-sql-functions"&gt;NHibernate - Customize the Linq provider to call your user defined SQL functions&lt;/a&gt; (10/1/2010)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="http://www.primordialcode.com/blog/post/the-nhibernate-day-is-coming.this-saturday"&gt;The NHibernate Day is coming...this Saturday!&lt;/a&gt; (10/6/2010)&lt;/li&gt;&lt;li style="list-style-type: none"&gt;&lt;a href="/Blog/Related/fetching-collections-nhibernate-mistake"&gt;&lt;strong&gt;More related document (21)&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=ofBa5zQlRvY:YlLQ7w-hghQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=ofBa5zQlRvY:YlLQ7w-hghQ:-BTjWOF_DHI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=ofBa5zQlRvY:YlLQ7w-hghQ:-BTjWOF_DHI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=ofBa5zQlRvY:YlLQ7w-hghQ:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=ofBa5zQlRvY:YlLQ7w-hghQ:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=ofBa5zQlRvY:YlLQ7w-hghQ:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=ofBa5zQlRvY:YlLQ7w-hghQ:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?i=ofBa5zQlRvY:YlLQ7w-hghQ:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PrimordialCode?a=ofBa5zQlRvY:YlLQ7w-hghQ:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PrimordialCode?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/PrimordialCode/~4/ofBa5zQlRvY" height="1" width="1"/&gt;&lt;img src="http://feeds.feedburner.com/~r/GuardiansHome/~4/8oIPTlQxu3E" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/GuardiansHome/~3/8oIPTlQxu3E/fetching-collections-nhibernate-mistake</link><author>Guardian</author><comments>http://www.primordialcode.com/blog/post/fetching-collections-nhibernate-mistake#feedback</comments><guid isPermaLink="false">http://www.primordialcode.com/blog/post/fetching-collections-nhibernate-mistake</guid><pubDate>Wed, 20 Jul 2011 00:52:37 GMT</pubDate><category>NHibernate</category><category>Fetch</category><feedburner:origLink>http://www.primordialcode.com/blog/post/fetching-collections-nhibernate-mistake</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/PrimordialCode/~3/ofBa5zQlRvY/fetching-collections-nhibernate-mistake</feedburner:origLink></item></channel></rss>

