<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Phillip Haydon</title>
	<atom:link href="http://www.philliphaydon.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.philliphaydon.com</link>
	<description>Works on my pc.</description>
	<lastBuildDate>Tue, 17 Jan 2012 13:09:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>RavenDB &#8211; Searching across multiple properties</title>
		<link>http://www.philliphaydon.com/2012/01/ravendb-searching-across-multiple-properties/</link>
		<comments>http://www.philliphaydon.com/2012/01/ravendb-searching-across-multiple-properties/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 13:09:57 +0000</pubDate>
		<dc:creator>Phillip</dc:creator>
				<category><![CDATA[RavenDB]]></category>
		<category><![CDATA[Index]]></category>
		<category><![CDATA[Map]]></category>
		<category><![CDATA[Searching]]></category>

		<guid isPermaLink="false">http://www.philliphaydon.com/2012/01/ravendb-searching-across-multiple-properties/</guid>
		<description><![CDATA[Ayende recently posted about Orders Search in RavenDB which got me a little bit excited, since I was pondering how I would do searching in RavenDB without having Full Text Searching from SQL Server. So digging into it I wanted to try it out for myself how to use it. Given the model:     public class [...]]]></description>
			<content:encoded><![CDATA[<p>Ayende recently posted about <a href="http://ayende.com/blog/152833/orders-search-in-ravendb" target="_blank">Orders Search</a> in RavenDB which got me a little bit excited, since I was pondering how I would do searching in RavenDB without having Full Text Searching from SQL Server.</p>
<p>So digging into it I wanted to try it out for myself how to use it. Given the model:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e098d48a-0962-4d48-bd3c-ba9758461f02" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;">    <span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">Post</span><br />     {<br />         <span style="color:#0000ff">public</span> <span style="color:#0000ff">int</span> Id { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br />         <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> Title { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br />         <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> Description { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br />         <span style="color:#0000ff">public</span> <span style="color:#2b91af">IEnumerable</span>&lt;<span style="color:#0000ff">string</span>&gt; Tags { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br />         <span style="color:#0000ff">public</span> <span style="color:#2b91af">DateTime</span> DatePosted { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br />     }</div>
</p></div>
</p></div>
<p>I’ve setup 10 posts (<a href="http://pastie.org/3200462" target="_blank">click here for the insert pastie</a>) just with some really basic data. </p>
<p>So I’m going to detail here all the data that I’ve setup.</p>
<h4>Tags</h4>
<table border="0" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td valign="top" width="200"><strong>Tag Name</strong></td>
<td valign="top" width="200"><strong># of Posts Containing Tag</strong></td>
</tr>
<tr>
<td valign="top" width="200">html</td>
<td valign="top" width="200">3</td>
</tr>
<tr>
<td valign="top" width="200">c#</td>
<td valign="top" width="200">6</td>
</tr>
<tr>
<td valign="top" width="200">ravendb</td>
<td valign="top" width="200">4</td>
</tr>
<tr>
<td valign="top" width="200">nhibernate</td>
<td valign="top" width="200">3</td>
</tr>
<tr>
<td valign="top" width="200">javascript</td>
<td valign="top" width="200">1</td>
</tr>
<tr>
<td valign="top" width="200">coffeescript</td>
<td valign="top" width="200">2</td>
</tr>
<tr>
<td valign="top" width="200">less</td>
<td valign="top" width="200">3</td>
</tr>
<tr>
<td valign="top" width="200">search</td>
<td valign="top" width="200">6</td>
</tr>
<tr>
<td valign="top" width="200">closures</td>
<td valign="top" width="200">1</td>
</tr>
<tr>
<td valign="top" width="200">jquery</td>
<td valign="top" width="200">2</td>
</tr>
<tr>
<td valign="top" width="200">css</td>
<td valign="top" width="200">1</td>
</tr>
<tr>
<td valign="top" width="200">queryover</td>
<td valign="top" width="200">2</td>
</tr>
<tr>
<td valign="top" width="200">mapreduce</td>
<td valign="top" width="200">4</td>
</tr>
</tbody>
</table>
<h4>Titles</h4>
<p>Nothing interesting, just ‘Test Post X’ for each one to identify them.</p>
<h4>Description</h4>
<p>Basically for this testing I’ve taken the blog post names of a few things from Google Reader, that some-way relate to the tags above. Take a look at the script mentioned above to see the data.</p>
<h4>Creating the Index</h4>
<p>So the first thing I want to do is create a Map with a Reduce Result, but we aren’t going to add the Reduce to the index, since we don’t need it to store that data or do anything with it. We purely want the Reduce Result that matches the map, so that we can query against it.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c58ee97b-64f7-4a26-bf75-9a98da20e32d" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">Post_Search</span> : <span style="color:#2b91af">AbstractIndexCreationTask</span>&lt;<span style="color:#2b91af">Post</span>, <span style="color:#2b91af">Post_Search</span>.<span style="color:#2b91af">ReduceResult</span>&gt;<br /> {<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">ReduceResult</span><br />     {<br />         <span style="color:#0000ff">public</span> <span style="color:#0000ff">object</span>[] SearchQuery { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br />         <span style="color:#0000ff">public</span> <span style="color:#2b91af">DateTime</span> DatePosted { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br />     }</p>
<p>     <span style="color:#0000ff">public</span> Post_Search()<br />     {<br />         Map = posts =&gt; <br />             <span style="color:#0000ff">from</span> post <span style="color:#0000ff">in</span> posts<br />             <span style="color:#0000ff">select</span> <span style="color:#0000ff">new</span> <br />             {<br />                 SearchQuery = post.Tags.Concat(<span style="color:#0000ff">new</span>[]<br />                                                 {<br />                                                     post.Description,<br />                                                     post.Title<br />                                                 }),<br />                 DatePosted = post.DatePosted<br />             };<br />     }<br /> }</div>
</p></div>
</p></div>
<p>This index is a little bit funky, and differs from what Ayende showed in his example. I wanted to try something a little different.</p>
<p>In my scenario I have a collection of Tag’s that I wanted to include in the search, this the tags is already a collection, I concatenate the additional array of items I want to add into the map.</p>
<p>The SearchQuery is the property that we will search against, while the DatePosted wont be included in the Search, but is there to provide additional filtering on my search.</p>
<h4>Querying</h4>
<p>Querying threw me off at first, because in order to query against this index, we have to specify the ReduceResult class.</p>
<p>So we end up with the starting of our query looking like this:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:62658a9c-5370-432d-973c-19b07c6fce09" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">var</span> result = session.Query&lt;<span style="color:#2b91af">Post_Search</span>.<span style="color:#2b91af">ReduceResult</span>, <span style="color:#2b91af">Post_Search</span>&gt;()</div>
</p></div>
</p></div>
<p>At first I thought “oh, that means we end up with a ReduceResult result type, this is pointless and useless”. But I commented on Ayende’s blog post and it turns out we can call ‘As&lt;T&gt;’ on the query.</p>
<p>Without filtering the results just yet, our query would look like the following:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6351c3b4-0cdb-4d8d-b2e4-52ed10c8bc88" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">var</span> result = session.Query&lt;<span style="color:#2b91af">Post_Search</span>.<span style="color:#2b91af">ReduceResult</span>, <span style="color:#2b91af">Post_Search</span>&gt;()<br />                     .As&lt;<span style="color:#2b91af">Post</span>&gt;()<br />                     .ToList();</div>
</p></div>
</p></div>
<p>So if I run this up now, for a quick test, I should get 10 results back of type Post</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2012/01/image.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2012/01/image_thumb.png" width="515" height="318" /></a></p>
<p>Great!</p>
<p>So now I need to begin filtering out the results. To begin with I’m doing to use the .Where extension. Since we are looking an object array, we can’t directly compare it to a string, but if we explicitly cast it to an object we can look for:</p>
<p>coffeescript expecting 2 results:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:52f8cdc9-d473-42bb-99e3-669a8f43cb8a" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">var</span> result = session.Query&lt;<span style="color:#2b91af">Post_Search</span>.<span style="color:#2b91af">ReduceResult</span>, <span style="color:#2b91af">Post_Search</span>&gt;()<br />                     .Where(x =&gt; x.SearchQuery == (<span style="color:#0000ff">object</span>)<span style="color:#a31515">&quot;coffeescript&quot;</span>)<br />                     .As&lt;<span style="color:#2b91af">Post</span>&gt;()<br />                     .ToList();</div>
</p></div>
</p></div>
<p>&#160;</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2012/01/image1.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2012/01/image_thumb1.png" width="531" height="97" /></a></p>
<p>How about javascript expecting 2 (1 via Tag and 1 via the Description)</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2012/01/image2.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2012/01/image_thumb2.png" width="503" height="90" /></a></p>
<p>Oh, we didn’t get the desired result… This is because the search is only doing a search on an exact match. Since the search value is an exact match of the tag, the result is returned.</p>
<p>So to fix this we need to make the index analysed. Adding to the index:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f54ff287-c280-4323-8097-b2759334cfbd" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;">Index(x =&gt; x.SearchQuery, <span style="color:#2b91af">FieldIndexing</span>.Analyzed);</div>
</p></div>
</p></div>
<p>If we run the exact same query again:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2012/01/image3.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2012/01/image_thumb3.png" width="546" height="121" /></a></p>
<p>Now we get 2 results.</p>
<p>Now to try something a little bit different, using ‘Search’, if we wanted to search for something like mvc which happens to only be in the description, rather than using ‘Where’ like shown above, we can use ‘Search’ like so:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9095a5dd-4d84-4615-bc50-e071606feb39" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">var</span> result = session.Query&lt;<span style="color:#2b91af">Post_Search</span>.<span style="color:#2b91af">ReduceResult</span>, <span style="color:#2b91af">Post_Search</span>&gt;()<br />                     .Search(x =&gt; x.SearchQuery, <span style="color:#a31515">&quot;mvc&quot;</span>)<br />                     .As&lt;<span style="color:#2b91af">Post</span>&gt;()<br />                     .ToList();</div>
</p></div>
</p></div>
<p>This will give us the same result, except it looks much cleaner</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2012/01/image4.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2012/01/image_thumb4.png" width="497" height="91" /></a></p>
<p>Now there’s 1 catch I’ve found with this, which is searching is always an exact match. I’m not sure (no research done into lucene yet) if lucene has the ability to do a wild-card type search similar to SQL like: ‘%mvc%’, but you can get suggestions from this.</p>
<p>For example if I search for ‘coffee’ rather than ‘coffeescript’ I would expect all documents containing ‘coffee’ to be returned. This doesn’t happen. It does give you suggestions though. </p>
<p>Looking at the management studio for ‘coffee’ :</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2012/01/image5.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2012/01/image_thumb5.png" width="350" height="181" /></a></p>
<p><em>Side Comment: I think it would be cool if RavenDB provided the ability to have say include suggestions, like:</em></p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b1921c36-651e-4bbc-95f9-408db15460bd" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">var</span> result = session.Query&lt;<span style="color:#2b91af">Post_Search</span>.<span style="color:#2b91af">ReduceResult</span>, <span style="color:#2b91af">Post_Search</span>&gt;()<br />                     .Search(x =&gt; x.SearchQuery, <span style="color:#a31515">&quot;coffee&quot;</span>)<br />                     .<span style="color:#ff0000">IncludeAllSuggestions</span>()<br />                     .As&lt;<span style="color:#2b91af">Post</span>&gt;()<br />                     .ToList();</div>
</p></div>
</p></div>
<p><em>Or other variations such as:</em></p>
<p><em>.Suggestions.IncludeAll()</em></p>
<p><em>.Suggestions.IncludeTop(3)</em></p>
<p><em></em></p>
<p><em>.Suggestions.IncludeAll(WhenResults.AreEmpty)</em></p>
<p><em></em></p>
<p><em>.Suggestions.IncludeAll(WhenResults.AreLessThan, 10)</em></p>
<p><em>Hopefully you can work out where I’m going with this?</em></p>
<p>Ok continuing on. Why do we need to call ‘As&lt;T&gt;()’ on the query?</p>
<p>Well from my understanding of how RavenDB works is like this, when we create an index, it’s creating a sub-set of data that points to the document in RavenDB.</p>
<p>For example I have all those documents inserted (<a href="http://pastie.org/3200462" target="_blank">link for the lazy</a>), and these are all stored like so:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2012/01/image6.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2012/01/image_thumb6.png" width="377" height="294" /></a></p>
<p>When we created the index with the following Map:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ee69f7f8-8e43-473a-ab8e-4771526286f0" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;">Map = posts =&gt; <br />     <span style="color:#0000ff">from</span> post <span style="color:#0000ff">in</span> posts<br />     <span style="color:#0000ff">select</span> <span style="color:#0000ff">new</span> <br />     {<br />         SearchQuery = post.Tags.Concat(<span style="color:#0000ff">new</span>[]<br />                                         {<br />                                             post.Description,<br />                                             post.Title<br />                                         }),<br />         DatePosted = post.DatePosted<br />     };</div>
</p></div>
</p></div>
<p>It basically created an index that looks like this, for the data above:</p>
<table style="width: 590px; height: 75px" border="0" cellspacing="0" cellpadding="2" width="591">
<tbody>
<tr>
<td valign="top" rowspan="2" width="50">posts/2</td>
<td valign="top" width="540">SearchQuery: [&quot;c#&quot;, &quot;nhibernate&quot;, &quot;search&quot;, &quot;queryover&quot;, &quot;Benjamin Day slides us into &quot;How to be a C# ninja in 10 easy steps&quot;&quot;, &quot;Test Post 2&quot;</td>
</tr>
<tr>
<td valign="top">DatePosted: &quot;2012-01-02T00:00:00.0000000&quot;</td>
</tr>
</tbody>
</table>
<p>So the index actually points directly to a Document in RavenDB, when we search against the index, if a match is found, the index returns the Id ‘posts/2’ back, and that knows to go to the posts collection and grab the document with Id 2.</p>
<p>The problem with the query is we need to specify an object to query against.</p>
<p>So we introduced the ReduceResult (<em>not sure on this naming but I took it from Ayende’s blog</em>), this allows us to specify the Properties we defined in our index, as search criteria, but now our query is expecting ReduceResult:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2012/01/image7.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2012/01/image_thumb7.png" width="633" height="99" /></a></p>
<p>By specifying as we are telling the query that our result is going to be a type of ‘Post’:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2012/01/image8.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2012/01/image_thumb8.png" width="601" height="113" /></a></p>
<h4>Conclusion</h4>
<p>This functionality is really cool, it allows us to easily search against multiple different properties without having to create messy conjunctions in our LINQ. If we were to attempt to do this without an index, we would probably end up writing something like:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ebee481a-84e0-4313-9006-bf4914d7b06d" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">var</span> result = session.Query&lt;<span style="color:#2b91af">Post</span>&gt;()<br />                     .Where(x =&gt;<br />                             x.Description.Contains(<span style="color:#a31515">&quot;c#&quot;</span>)<br />                             ||<br />                             x.Tags.Any(y =&gt; y == <span style="color:#a31515">&quot;c#&quot;</span>)<br />                             ||<br />                             x.Title.Contains(<span style="color:#a31515">&quot;c#&quot;</span>)<br />                         )<br />                     .ToList();</div>
</p></div>
</p></div>
<p>And really, that’s just nasty… Specially considering we get the same results for writing more readable code:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2012/01/image9.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2012/01/image_thumb9.png" width="442" height="264" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.philliphaydon.com/2012/01/ravendb-searching-across-multiple-properties/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RavenDB &#8211; Map Reduce</title>
		<link>http://www.philliphaydon.com/2011/12/ravendb-map-reduce/</link>
		<comments>http://www.philliphaydon.com/2011/12/ravendb-map-reduce/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 13:18:55 +0000</pubDate>
		<dc:creator>Phillip</dc:creator>
				<category><![CDATA[RavenDB]]></category>

		<guid isPermaLink="false">http://www.philliphaydon.com/2011/12/ravendb-map-reduce/</guid>
		<description><![CDATA[So, learning Map Reduce in RavenDB I decided that to take what I learnt from the index created in my previous post. I think I picked something rather difficult to begin with, but I’ve succeeded Given a document Article which has a collection of Tags. I want to get a Count of each Tag across [...]]]></description>
			<content:encoded><![CDATA[<p>So, learning Map Reduce in RavenDB I decided that to take what I learnt from the index created in my <a href="http://www.philliphaydon.com/2011/12/ravendb-inheritance-revisited/" target="_blank">previous post</a>. I think I picked something rather difficult to begin with, but I’ve succeeded <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/wlEmoticon-smile1.png" /></p>
<p>Given a document Article which has a collection of Tags.</p>
<p>I want to get a Count of each Tag across all Articles.</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:04420726-90d7-44e4-971c-b27806e72f3e" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">Content</span><br /> {<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">int</span> Id { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> Title { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }</p>
<p>     <span style="color:#0000ff">public</span> <span style="color:#2b91af">IEnumerable</span>&lt;<span style="color:#2b91af">Tag</span>&gt; Tags { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br /> }</p>
<p> <span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">Tag</span><br /> {<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> Name { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br /> }</div>
</p></div>
</p></div>
</p>
<p><em>Note: Tag is it’s own class because I added additional properties to it. </em></p>
<p>Now I insert some data:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d9ccd028-4730-41ac-bd15-bf927c5ae357" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">using</span> (<span style="color:#0000ff">var</span> session = documentStore.OpenSession())<br /> {<br />     session.Store(<span style="color:#0000ff">new</span> <span style="color:#2b91af">Content</span><br />     {<br />         Title = <span style="color:#a31515">&quot;Test Title for a Video&quot;</span>,<br />         Tags = <span style="color:#0000ff">new</span> <span style="color:#2b91af">List</span>&lt;<span style="color:#2b91af">Tag</span>&gt;<br />         {<br />             <span style="color:#0000ff">new</span> <span style="color:#2b91af">Tag</span>() {Name = <span style="color:#a31515">&quot;c#&quot;}</span>,<br />             <span style="color:#0000ff">new</span> <span style="color:#2b91af">Tag</span>() {Name = <span style="color:#a31515">&quot;autofac&quot;}</span>,<br />             <span style="color:#0000ff">new</span> <span style="color:#2b91af">Tag</span>() {Name = <span style="color:#a31515">&quot;asp.net&quot;}</span>,<br />         }<br />     });<br />     session.Store(<span style="color:#0000ff">new</span> <span style="color:#2b91af">Content</span><br />     {<br />         Title = <span style="color:#a31515">&quot;Test Title for an Article&quot;</span>,<br />         Tags = <span style="color:#0000ff">new</span> <span style="color:#2b91af">List</span>&lt;<span style="color:#2b91af">Tag</span>&gt;<br />         {<br />             <span style="color:#0000ff">new</span> <span style="color:#2b91af">Tag</span>() {Name = <span style="color:#a31515">&quot;c#&quot;}</span>,<br />             <span style="color:#0000ff">new</span> <span style="color:#2b91af">Tag</span>() {Name = <span style="color:#a31515">&quot;nhibernate&quot;}</span>,<br />             <span style="color:#0000ff">new</span> <span style="color:#2b91af">Tag</span>() {Name = <span style="color:#a31515">&quot;fluent-nhibernate&quot;}</span>,<br />             <span style="color:#0000ff">new</span> <span style="color:#2b91af">Tag</span>() {Name = <span style="color:#a31515">&quot;mvc&quot;}</span><br />         }<br />     });<br />     session.Store(<span style="color:#0000ff">new</span> <span style="color:#2b91af">Content</span><br />     {<br />         Title = <span style="color:#a31515">&quot;Test Title for an Article&quot;</span>,<br />         Tags = <span style="color:#0000ff">new</span> <span style="color:#2b91af">List</span>&lt;<span style="color:#2b91af">Tag</span>&gt;<br />         {<br />             <span style="color:#0000ff">new</span> <span style="color:#2b91af">Tag</span>() {Name = <span style="color:#a31515">&quot;ravendb&quot;}</span>,<br />             <span style="color:#0000ff">new</span> <span style="color:#2b91af">Tag</span>() {Name = <span style="color:#a31515">&quot;asp.net&quot;}</span>,<br />             <span style="color:#0000ff">new</span> <span style="color:#2b91af">Tag</span>() {Name = <span style="color:#a31515">&quot;autofac&quot;}</span>,<br />             <span style="color:#0000ff">new</span> <span style="color:#2b91af">Tag</span>() {Name = <span style="color:#a31515">&quot;c#&quot;}</span><br />         }<br />     });</p>
<p>     session.SaveChanges();<br /> }</div>
</p></div>
</p></div>
<p>&#160;</p>
<p>So I’m expecting a count of:</p>
<ul>
<li>3 x c#</li>
<li>2 x autofac</li>
<li>2 x asp.net</li>
<li>1 x ravendb</li>
<li>1 x mvc</li>
<li>1 x nhibernate</li>
<li>1 x fluent-nhibernate</li>
<p>I’m going to pull these out with a defined type rather than dynamic/object, so I’ve created a new class with Count and Name:</ul>
<ul>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:87501ae5-1b35-4beb-a7e4-8d9cc8d6392c" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">TagResult</span><br /> {<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">int</span>      Count   { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span>   Name    { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br /> }</div>
</p></div>
</p></div>
</ul>
<p>So creating a new Index:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1d6733ce-4692-46d8-b4dc-cfb8b41f153d" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">All_Tags</span> : <span style="color:#2b91af">AbstractMultiMapIndexCreationTask</span>&lt;<span style="color:#2b91af">TagResult</span>&gt;<br /> {<br />     <span style="color:#0000ff">public</span> All_Tags()<br />     {<br />     }<br /> }</div>
</p></div>
</p></div>
<p>The first thing I need to do is map out ONLY the Tag’s, when I select out the Tag’s, I’m also going to include another field called Count, with a default value of 1. This is so I can re-use it to sum the total number of times the tag is used.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ec9d7429-176e-4338-8b07-aa6113df183d" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;">AddMap&lt;<span style="color:#2b91af">Content</span>&gt;(contents =&gt; <span style="color:#0000ff">from</span> content <span style="color:#0000ff">in</span> contents<br />                             <span style="color:#0000ff">from</span> tag <span style="color:#0000ff">in</span> content.Tags<br />                             <span style="color:#0000ff">select</span> <span style="color:#0000ff">new</span><br />                             {<br />                                 Name = tag.Name,<br />                                 Count = 1<br />                             });</div>
</p></div>
</p></div>
<p>This would give me a result that contains duplicates for the tags. Along the lines of:</p>
<table border="1" cellspacing="0" cellpadding="2" width="398">
<tbody>
<tr>
<td valign="top" width="203">c#</td>
<td valign="top" width="193">1</td>
</tr>
<tr>
<td valign="top" width="204">c#</td>
<td valign="top" width="192">1</td>
</tr>
<tr>
<td valign="top" width="205">c#</td>
<td valign="top" width="192">1</td>
</tr>
<tr>
<td valign="top" width="205">autofac</td>
<td valign="top" width="192">1</td>
</tr>
<tr>
<td valign="top" width="205">autofac</td>
<td valign="top" width="192">1</td>
</tr>
<tr>
<td valign="top" width="205">asp.net</td>
<td valign="top" width="192">1</td>
</tr>
<tr>
<td valign="top" width="205">asp.net</td>
<td valign="top" width="192">1</td>
</tr>
<tr>
<td valign="top" width="205">ravendb</td>
<td valign="top" width="192">1</td>
</tr>
<tr>
<td valign="top" width="205">mvc</td>
<td valign="top" width="192">1</td>
</tr>
<tr>
<td valign="top" width="205">nhibernate</td>
<td valign="top" width="192">1</td>
</tr>
<tr>
<td valign="top" width="205">fluent-nhibernate</td>
<td valign="top" width="192">1</td>
</tr>
</tbody>
</table>
<p>So what I need to do in the Reduce, is group the tags together by their Name.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f2f0fd2a-3036-4bd4-a39b-7d0ee628b4d0" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;">Reduce = results =&gt; <span style="color:#0000ff">from</span> result <span style="color:#0000ff">in</span> results<br />                     <span style="color:#0000ff">group</span> result <span style="color:#0000ff">by</span> result.Name <span style="color:#0000ff">into</span> tag<br />                     <span style="color:#0000ff">select</span> <span style="color:#0000ff">new</span><br />                     {<br />                         Count = tag.Sum(x =&gt; x.Count),<br />                         Name = tag.Key,<br />                     };</div>
</p></div>
</p></div>
<p>So here, I group all the tags together by their name, but I also sum the ‘count’ value together to get the total number of times the tag is used.</p>
<p>Now run up the app and view the index:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image19.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb19.png" width="593" height="358" /></a></p>
<p>Now if I query the index:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image20.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb20.png" width="553" height="319" /></a></p>
<p>Awesome. Now to query this, I have to use the TagResult class defined previously, and the All_Tags index just created.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a80a8491-8c43-4aaf-bf8e-e013a43b7278" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">using</span> (<span style="color:#0000ff">var</span> session = documentStore.OpenSession())<br /> {<br />     <span style="color:#0000ff">var</span> result = session.Query&lt;<span style="color:#2b91af">TagResult</span>, <span style="color:#2b91af">All_Tags</span>&gt;()<br />                         .ToList();</p>
<p>     <span style="color:#0000ff">foreach</span> (<span style="color:#0000ff">var</span> tag <span style="color:#0000ff">in</span> result)<br />     {<br />         <span style="color:#2b91af">Console</span>.WriteLine(tag.Count + <span style="color:#a31515">&quot; x &quot;</span> + tag.Name);<br />     }</p>
<p>     session.SaveChanges();<br /> }</div>
</p></div>
</p></div>
<p>Running this I get the following result:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image21.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb21.png" width="196" height="125" /></a></p>
<p>The results I expected previously. </p>
<p>So there you have it. Map Reduce. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.philliphaydon.com/2011/12/ravendb-map-reduce/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RavenDB Inheritance&#8211;Revisited</title>
		<link>http://www.philliphaydon.com/2011/12/ravendb-inheritance-revisited/</link>
		<comments>http://www.philliphaydon.com/2011/12/ravendb-inheritance-revisited/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 13:35:21 +0000</pubDate>
		<dc:creator>Phillip</dc:creator>
				<category><![CDATA[RavenDB]]></category>

		<guid isPermaLink="false">http://www.philliphaydon.com/2011/12/ravendb-inheritancerevisited/</guid>
		<description><![CDATA[So after my initial post on RavenDB Inheritance, and the issue I had with polymorphic queries, and seeking help from the guys in JabbR and the RavenDB Google Group, Ayende ended up doing a screen cast with me where he solved all my problems. One of the things he asked me was what I was [...]]]></description>
			<content:encoded><![CDATA[<p>So after my initial post on <a href="http://www.philliphaydon.com/2011/12/ravendb-inheritance/" target="_blank">RavenDB Inheritance</a>, and the issue I had with polymorphic queries, and seeking help from the guys in <a href="http://jabbr.net" target="_blank">JabbR</a> and the <a href="http://groups.google.com/group/ravendb/browse_thread/thread/c71df8f1cd92e04c" target="_blank">RavenDB Google Group</a>, <a href="http://ayende.com/blog/" target="_blank">Ayende</a> ended up doing a screen cast with me where he solved all my problems.</p>
<p>One of the things he asked me was what I was trying to achieve by having a polymorphic query, which was a very good question, something I hadn’t really thought about.</p>
<p>The problem I was trying to solve was actually displaying search results. </p>
<h3>The Problem</h3>
<p>So I’m working on a personal project, and I need to display a few things which are similar, but different. There’s 3 different types but I’ll use two to keep it simple. I’ve also cut out most of the properties.</p>
<p>So I have an abstract class Content, with two derived classes, Article and Video.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d4143260-3181-45c4-8e29-5100ade2fd35" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">abstract</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">Content</span><br /> {<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">int</span> Id { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> Title { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br />     <span style="color:#0000ff">public</span> <span style="color:#2b91af">DateTime</span> DatePublished { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br /> }</p>
<p> <span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">Article</span> : <span style="color:#2b91af">Content</span><br /> {<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> HtmlContent { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br /> }</p>
<p> <span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">Video</span> : <span style="color:#2b91af">Content</span><br /> {<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> Description { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> VideoUrl { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br /> }</div>
</p></div>
</p></div>
<p>Then I initialize the DocumentStore and store a couple of documents.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6c5cdcff-4ca5-4183-9d41-40590b98d1fc" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">var</span> documentStore =<br />     (<span style="color:#0000ff">new</span> <span style="color:#2b91af">DocumentStore</span>()<br />             {<br />                 Url = <span style="color:#a31515">&quot;http://localhost:8080&quot;</span><br />             }).Initialize();</p>
<p> <span style="color:#0000ff">using</span> (<span style="color:#0000ff">var</span> session = documentStore.OpenSession())<br /> {<br />     session.Store(<span style="color:#0000ff">new</span> <span style="color:#2b91af">Video</span><br />     {<br />         DatePublished = <span style="color:#2b91af">DateTime</span>.Now,<br />         Description = <span style="color:#a31515">&quot;Test Description for a Video&quot;</span>,<br />         Title = <span style="color:#a31515">&quot;Test Title for a Video&quot;</span>,<br />         VideoUrl = <span style="color:#a31515">&quot;http://www.youtube.com/watch?v=PGz9GokDkkg&quot;</span><br />     });</p>
<p>     session.Store(<span style="color:#0000ff">new</span> <span style="color:#2b91af">Article</span><br />     {<br />         DatePublished = <span style="color:#2b91af">DateTime</span>.Now,<br />         Title = <span style="color:#a31515">&quot;Test Title for an Article&quot;</span>,<br />         HtmlContent = <span style="color:#a31515">&quot;Some content for the article&#8230;&quot;</span><br />     });</p>
<p>     session.SaveChanges();<br /> }</div>
</p></div>
</p></div>
<p>This time I’m not using the Convention to store the two documents as ‘Content’, rather I’m allowing it to store them as what they are. This gives me a result in Raven like:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image13.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb13.png" width="569" height="135" /></a></p>
<p>Now if I query for Video:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d47138bf-a045-40c7-a881-158fff07d0a1" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">using</span> (<span style="color:#0000ff">var</span> session = documentStore.OpenSession())<br /> {<br />     <span style="color:#0000ff">var</span> result = session.Query&lt;<span style="color:#2b91af">Video</span>&gt;().ToList();<br />     <br />     <span style="color:#0000ff">foreach</span> (<span style="color:#0000ff">var</span> content <span style="color:#0000ff">in</span> result)<br />     {<br />         <span style="color:#2b91af">Console</span>.WriteLine(content.Id);<br />         <span style="color:#2b91af">Console</span>.WriteLine(content.Title);<br />     }<br /> }</div>
</p></div>
</p></div>
<p>I get the output of the first Document.</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image14.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb14.png" width="194" height="42" /></a></p>
<p>Likewise if I select ‘Article’ I get the Article document that I previously stored. </p>
<p>So how do I get a list of Content?</p>
<h3>The Solution</h3>
<p>So, the solution is really, really easy, it’s an index.</p>
<p>The first thing Ayende showed me was creating the index in RavenDB Management Studio, then he showed me doing it in code. I’m just going to show it done in code.</p>
<p>I created a class called ‘All_Content’ (with an underscore) like so:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:22895285-ad0f-4f8a-aee3-941be029b305" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">All_Content</span> : <span style="color:#2b91af">AbstractMultiMapIndexCreationTask</span><br /> {<br />     <span style="color:#0000ff">public</span> All_Content()<br />     {<br />         AddMap&lt;<span style="color:#2b91af">Article</span>&gt;(articles =&gt; <span style="color:#0000ff">from</span> article <span style="color:#0000ff">in</span> articles<br />                                     <span style="color:#0000ff">select</span> <span style="color:#0000ff">new</span><br />                                                 {<br />                                                     article.Id,<br />                                                     article.Title,<br />                                                     article.DatePublished<br />                                                 });<br />         AddMap&lt;<span style="color:#2b91af">Video</span>&gt;(videos =&gt; <span style="color:#0000ff">from</span> video <span style="color:#0000ff">in</span> videos<br />                                 <span style="color:#0000ff">select</span> <span style="color:#0000ff">new</span><br />                                             {<br />                                                 video.Id,<br />                                                 video.Title,<br />                                                 video.DatePublished<br />                                             });<br />     }<br /> }</div>
</p></div>
</p></div>
<p><em><u>It reminds me of writing a Union View in SQL Server in some ways.</u></em> It basically maps to the Articles and Videos, but only selects the things I need. Those of which would actually be displayed to the screen or that are common between the two document types. </p>
<p>Then I create the index right after I initialize the DocumentStore:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:25a91885-4105-48a6-a61a-122396738e3d" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#2b91af">IndexCreation</span>.CreateIndexes(<span style="color:#0000ff">typeof</span>(<span style="color:#2b91af">All_Content</span>).Assembly, documentStore);</div>
</p></div>
</p></div>
<p>This creates the index in RavenDB for me. </p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image15.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb15.png" width="410" height="148" /></a></p>
<p>As you can see, even tho I specified the class index with an underscore, it converts it to All/Content, that’s a really nice way of presenting it. I think it will go well for being able to create descriptive indexes in the future.</p>
<p>And the index itself:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image16.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb16.png" width="559" height="331" /></a></p>
<p>Now I need to actually query against the index. That’s also really really easy. When I specify the type, I can specify the index with it:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:bce100ee-db39-4015-942f-37d0fcee7ad4" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">using</span> (<span style="color:#0000ff">var</span> session = documentStore.OpenSession())<br /> {<br />     <span style="color:#0000ff">var</span> result = session.Query&lt;<span style="color:#2b91af">Content</span>, <span style="color:#2b91af">All_Content</span>&gt;().ToList();<br />     <br />     <span style="color:#0000ff">foreach</span> (<span style="color:#0000ff">var</span> content <span style="color:#0000ff">in</span> result)<br />     {<br />         <span style="color:#2b91af">Console</span>.WriteLine(content.Id);<br />         <span style="color:#2b91af">Console</span>.WriteLine(content.Title);<br />     }<br /> }</div>
</p></div>
</p></div>
<p>Now when I run this I get the output:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image17.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb17.png" width="225" height="81" /></a></p>
<p>Awesome!</p>
<p>The really interesting thing I found is that if I look at what’s returned:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image18.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb18.png" width="465" height="133" /></a></p>
<p>Are the correct CLR types that I originally defined. So I haven’t lost all the additional fields by not defining them. I’m still learning but for now I assume it allows those fields to be searchable.</p>
<h3>Extras</h3>
<p>One of the additional things Ayende showed me was that you can include other documents that don’t inherit from the base type. You can include those in the index map, and then rather than returning a concrete type, you can specify object, or dynamic.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:723fa54e-8c1e-414f-ab77-b9c2d667a1c5" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">var</span> result = session.Query&lt;<span style="color:#0000ff">dynamic</span>, <span style="color:#2b91af">All_Content</span>&gt;().ToList();</div>
</p></div>
</p></div>
<p>RavenDB is really powerful. It’s truly amazing, and so much nicer to work with in .NET than other document databases like MongoDB.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.philliphaydon.com/2011/12/ravendb-inheritance-revisited/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RavenDB Inheritance</title>
		<link>http://www.philliphaydon.com/2011/12/ravendb-inheritance/</link>
		<comments>http://www.philliphaydon.com/2011/12/ravendb-inheritance/#comments</comments>
		<pubDate>Sat, 10 Dec 2011 05:20:42 +0000</pubDate>
		<dc:creator>Phillip</dc:creator>
				<category><![CDATA[RavenDB]]></category>

		<guid isPermaLink="false">http://www.philliphaydon.com/2011/12/ravendb-inheritance/</guid>
		<description><![CDATA[Edit: Updated solution: http://www.philliphaydon.com/2011/12/ravendb-inheritance-revisited/ Continuing my learning of RavenDB, I wanted to see how it handled Inheritance. I found: http://ravendb.net/faq/polymorphic-indexes Which showed what to do allow you to select over all types of ‘Animal’ for the example shown. So I wanted to see what happens before and after using this method. So like the example [...]]]></description>
			<content:encoded><![CDATA[<p><em><font color="#ff0000">Edit: Updated solution: </font></em><a title="http://www.philliphaydon.com/2011/12/ravendb-inheritance-revisited/" href="http://www.philliphaydon.com/2011/12/ravendb-inheritance-revisited/"><em><font color="#ff0000">http://www.philliphaydon.com/2011/12/ravendb-inheritance-revisited/</font></em></a></p>
<p>Continuing my learning of RavenDB, I wanted to see how it handled Inheritance. </p>
<p>I found: <a href="http://ravendb.net/faq/polymorphic-indexes">http://ravendb.net/faq/polymorphic-indexes</a></p>
<p>Which showed what to do allow you to select over all types of ‘Animal’ for the example shown. So I wanted to see what happens before and after using this method.</p>
<p>So like the example shown I’ve created an Animal, with a Dog and Cat.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5103027d-87bc-4b5b-8f85-3f22f22a9fa3" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">abstract</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">Animal</span><br /> {<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">int</span> Id { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> Name { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br /> }</p>
<p> <span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">Dog</span> : <span style="color:#2b91af">Animal</span> { }<br /> <span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">Cat</span> : <span style="color:#2b91af">Animal</span> { }</div>
</p></div>
</p></div>
<p>Now if I insert a Dog and Cat:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e99f0b1b-6547-47ba-819b-b2b9cc97da45" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">using</span> (<span style="color:#0000ff">var</span> session = documentStore.OpenSession())<br /> {<br />     session.Store(<span style="color:#0000ff">new</span> <span style="color:#2b91af">Dog</span>() { Name = <span style="color:#a31515">&quot;Test Dog&quot;</span> });<br />     session.Store(<span style="color:#0000ff">new</span> <span style="color:#2b91af">Cat</span>() { Name = <span style="color:#a31515">&quot;Test Cat&quot;</span> });</p>
<p>     session.SaveChanges();<br /> }</div>
</p></div>
</p></div>
<p>What’s stored in RavenDB is two separate documents, one for ‘dogs’ and one for ‘cats’.</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image7.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb7.png" width="527" height="109" /></a></p>
<p>If I include the Convention.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d8d84704-0e7b-4bd2-bdc8-5c0919175343" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">var</span> documentConvention =<br />     <span style="color:#0000ff">new</span> <span style="color:#2b91af">DocumentConvention</span>()<br />         {<br />             FindTypeTagName =<br />                 type =&gt;<br />                     {<br />                         <span style="color:#0000ff">if</span> (<span style="color:#0000ff">typeof</span> (<span style="color:#2b91af">Animal</span>).IsAssignableFrom(type))<br />                             <span style="color:#0000ff">return</span> <span style="color:#a31515">&quot;animals&quot;</span>;<br />                         <span style="color:#0000ff">return</span> <span style="color:#2b91af">DocumentConvention</span>.DefaultTypeTagName(type);<br />                     }<br />         };</div>
</p></div>
</p></div>
<p><em>Note: You can do the conversion when the DocumentStore is initialized, I broke the two up so that it would fit easier into my blog. Otherwise it’s too nested and yucky.</em></p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:96302d95-1d97-4482-a3ec-63bdb1a4739c" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">var</span> documentStore =<br />     (<span style="color:#0000ff">new</span> <span style="color:#2b91af">DocumentStore</span>()<br />             {<br />                 Url = <span style="color:#a31515">&quot;http://localhost:8080&quot;</span>,<br />                 Conventions = documentConvention<br />             }).Initialize();</div>
</p></div>
</p></div>
<p>Now when I insert a Dog and Cat I get:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image8.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb8.png" width="401" height="110" /></a></p>
<p>Awesome. If we look at the document however:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image9.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb9.png" width="220" height="177" /></a></p>
<p>There is no information about it being a cat or dog, I thought it would add some sort of discriminator similar to how NHibernate works.</p>
<p>However, if we look at the Metadata tab:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image10.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb10.png" width="412" height="194" /></a></p>
<p>We can see the CLR type is stored in the metadata so RavenDB knows what type to create when we query it.</p>
<p>This means if we query for ‘Animal’ we get a list of Dogs and Cats.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:82ff679f-4f56-477f-9212-69aade2508b3" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">using</span> (<span style="color:#0000ff">var</span> session = documentStore.OpenSession())<br /> {<br />     <span style="color:#0000ff">var</span> result = session.Query&lt;<span style="color:#2b91af">Animal</span>&gt;();</p>
<p>     <span style="color:#0000ff">foreach</span> (<span style="color:#0000ff">var</span> animal <span style="color:#0000ff">in</span> result)<br />     {<br />         <span style="color:#2b91af">Console</span>.WriteLine(animal.Name);<br />     }<br /> }</div>
</p></div>
</p></div>
<p>&#160;</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image11.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb11.png" width="375" height="131" /></a></p>
<p>However, if you wanted to query for just Dogs, like so:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:51adf224-e32f-45fd-9baf-7670a6407a1a" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">var</span> result = session.Query&lt;<span style="color:#2b91af">Dog</span>&gt;().ToList();</div>
</p></div>
</p></div>
<p>It doesn’t seem to work <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-sadsmile" alt="Sad smile" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/wlEmoticon-sadsmile1.png" /></p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image12.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb12.png" width="437" height="104" /></a></p>
<p>I’m probably just doing something wrong, either way, the more I play with RavenDB. The more I love it. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.philliphaydon.com/2011/12/ravendb-inheritance/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Post a collection of ViewModel&#8217;s to a MVC Action with jQuery</title>
		<link>http://www.philliphaydon.com/2011/12/post-a-collection-of-viewmodels-to-a-mvc-action-with-jquery/</link>
		<comments>http://www.philliphaydon.com/2011/12/post-a-collection-of-viewmodels-to-a-mvc-action-with-jquery/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 12:13:37 +0000</pubDate>
		<dc:creator>Phillip</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://www.philliphaydon.com/2011/12/post-a-collection-of-viewmodels-to-a-mvc-action-with-jquery/</guid>
		<description><![CDATA[Maybe I searched for the wrong thing, but I couldn’t find what I was looking for My Bing and Google fu failed me. Basically I wanted to post a collection of ViewModels to an MCV action. Turns out it’s rather simple. Lets say I have a bunch of Products, and Products are managed in a [...]]]></description>
			<content:encoded><![CDATA[<p>Maybe I searched for the wrong thing, but I couldn’t find what I was looking for <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-sadsmile" alt="Sad smile" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/wlEmoticon-sadsmile.png" /> My Bing and Google fu failed me.</p>
<p>Basically I wanted to post a collection of ViewModels to an MCV action. Turns out it’s rather simple.</p>
<p>Lets say I have a bunch of Products, and Products are managed in a WarehouseLocation. A product doesn’t have a warehouse location, since it could exist in multiple locations. </p>
<p>If I’m currently working in Location A, I want to post a collection of Products to an action, as well as the WarehouseLocationId.</p>
<p>So given a simple ViewModel, and an Action:</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:30a8a5ec-35f3-40a1-897f-f008a1de693d" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">ProductViewModel</span><br /> {<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">int</span> Id { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> Name { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">decimal</span> Price { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br /> }</div>
</p></div>
</p></div>
</p>
<p>and</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:52efada5-5114-4d42-9003-bf9798eeb7ec" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#2b91af">JsonResult</span> Update(<span style="color:#0000ff">int</span> warehouseLocationId, <span style="color:#2b91af">IEnumerable</span>&lt;<span style="color:#2b91af">ProductViewModel</span>&gt; products)<br /> {<br />     <span style="color:#008000">//Do something with the products&#8230;</span></p>
<p>     <span style="color:#0000ff">return</span> Json(<span style="color:#0000ff">new</span> {Staus = <span style="color:#a31515">&quot;success&quot;}</span>);<br /> }</div>
</p></div>
</p></div>
<p>I think usually when someone sends data from jQuery it’s usually a single parameter,so the JSON would look something like:</p>
<p><em>var data = { id: 1,name: ‘test name’, price: 15.95 };</em></p>
<p>This would populate an action that looked like:</p>
<p><em>public JsonResult Update(ProductViewModel product)</em></p>
<p>But what I was faced with was passing in two parameters, one of which is a collection…</p>
<p>MVC seems to pair up the posted result with the parameter name, in the same way they it does for Route parameters. So to the JSON needs to look like:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d1908b0a-71d9-41b9-bd6a-22cbd3cdaed5" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">var</span> data = {<br />     warehouseLocationId: 12,<br />     products: [{<br />         Id: 1,<br />         Name: <span style="color:#800000">&quot;Product 1&quot;</span>,<br />         Price: 15.95<br />     }, {<br />         Id: 3,<br />         Name: <span style="color:#800000">&quot;Product 2&quot;</span>,<br />         Price: 12.50<br />     }]<br /> };</div>
</p></div>
</p></div>
<p>As you can see the key’s on the first level match the parameter names, while the array on products, match the ViewModel.</p>
<p>Taking this exact data and posting it to the action:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4e484c30-a717-44de-98ac-b4aaceab8df8" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;">$.ajax({<br />         type: &#39;POST&#39;,<br />         url: &#39;<span style="background:#ffff00">@</span>Url.Action(<span style="color:#a31515">&quot;Update&quot;</span>, <span style="color:#a31515">&quot;Home&quot;</span>)&#39;,<br />         data: JSON.stringify(data),<br />         contentType: &#39;application/json&#39;,<br />         success: function(result) {<br />             //Do something with result&#8230;<br />         },<br />         dataType: &#39;json&#39;<br />     });</div>
</p></div>
</p></div>
<p>&#160;</p>
<p>I submit that, and with a breakpoint on my action I see:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb.png" width="343" height="43" /></a></p>
<p>^ The warehouseLocationId…</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image1.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb1.png" width="640" height="99" /></a></p>
<p>^ 2 products with the values:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image2.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb2.png" width="387" height="115" /></a></p>
<p>And:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image3.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb3.png" width="373" height="137" /></a></p>
<p>The exact same data we defined in our JavaScript.</p>
<p>The really cool thing about this, is you can have nested collections also. Using the same scenario, but extending Product to have a collection of Categories like so:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d86ddfe3-e941-4ba7-8f46-bc1f090b7f0d" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">ProductViewModel</span><br /> {<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">int</span> Id { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> Name { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">decimal</span> Price { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }</p>
<p>     <span style="color:#0000ff">public</span> <span style="color:#2b91af">IEnumerable</span>&lt;<span style="color:#2b91af">Category</span>&gt; Categories { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br /> }</p>
<p> <span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">Category</span><br /> {<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">int</span> Id { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> Name { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br /> }</div>
</p></div>
</p></div>
<p>I can update the JSON object to include Category information on 1 of the two products:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:887c08e4-93ff-463b-b0e2-b562b5cc6263" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;">var data = {<br />     warehouseLocationId: 12,<br />     products: [{<br />         Id: 1,<br />         Name: &quot;Product 1&quot;,<br />         Price: 15.95<br />     }, {<br />         Id: 3,<br />         Name: &quot;Product 2&quot;,<br />         Price: 12.50,<br />         Categories: [{<br />             Id: 1,<br />             Name: &quot;Category 1&quot;<br />         }, {<br />             Id: 1,<br />             Name: &quot;Category 2&quot;<br />         }]<br />     }]<br /> };</div>
</p></div>
</p></div>
<p>And submit that in the same way as before, capturing the results in the Action we get the first product with null for the categories, since we didn’t define it as an empty array:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image4.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb4.png" width="380" height="135" /></a></p>
<p>While the second Product has 2 items, the first item is Category 1, and the second item is Category 2.</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image5.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb5.png" width="404" height="156" /></a></p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/12/image6.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/image_thumb6.png" width="381" height="172" /></a></p>
<p>And that’s it, easy peasy, sending a collection of ViewModels from jQuery to an MVC Action. </p>
<p>I &lt;3 MVC <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://www.philliphaydon.com/wp-content/uploads/2011/12/wlEmoticon-smile.png" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.philliphaydon.com/2011/12/post-a-collection-of-viewmodels-to-a-mvc-action-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Split Windows + Web Workbench = Win</title>
		<link>http://www.philliphaydon.com/2011/11/split-windows-web-workbench-win/</link>
		<comments>http://www.philliphaydon.com/2011/11/split-windows-web-workbench-win/#comments</comments>
		<pubDate>Sun, 27 Nov 2011 02:49:17 +0000</pubDate>
		<dc:creator>Phillip</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[LESS]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Web Workbench]]></category>

		<guid isPermaLink="false">http://www.philliphaydon.com/2011/11/split-windows-web-workbench-win/</guid>
		<description><![CDATA[One of the cool features of the Web Workbench from Mindscape is the ability to generate the output files. Prior to using the Web Workbench I was using .LESS{} which uses an HTTP Handler to generate the output files for LESS. The problem with this is sometimes I would write some CSS and not realise [...]]]></description>
			<content:encoded><![CDATA[<p>One of the cool features of the <a href="http://www.mindscapehq.com/products/web-workbench/">Web Workbench</a> from Mindscape is the ability to generate the output files. Prior to using the Web Workbench I was using <a href="http://www.dotlesscss.org/">.LESS{}</a> which uses an HTTP Handler to generate the output files for LESS.</p>
<p>The problem with this is sometimes I would write some CSS and not realise I missed something only to find my site doesn’t display anything, then I have to figure out what I did wrong.</p>
<p>With the Web Workbench, and it’s ability to generate the files every time I save, makes me less error prone.</p>
<p>But the most efficient way of working with it I found (when writing a lot of CSS in 1 sitting) is to split my windows so the first window has where I’m writing, and the second window has the generated CSS file.</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/11/image7.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/11/image_thumb7.png" width="585" height="394" /></a></p>
<p>If I make an error on the left side:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/11/image8.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/11/image_thumb8.png" width="585" height="394" /></a></p>
<p>I see the error on the right. </p>
<p>If I make a change to the left, (added a background colour) i see the change on the right.</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/11/image9.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/11/image_thumb9.png" width="585" height="394" /></a></p>
<p>This makes it really handy when applying nested rules. Such as nesting a hover rule to an anchor tag. Sometimes I forget to include the colon.</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/11/image10.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/11/image_thumb10.png" width="585" height="394" /></a></p>
<p>Maybe in the next version of the Web Bench, Mindscape can include side-by-side windows that scroll with each other <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.philliphaydon.com/wp-content/uploads/2011/11/wlEmoticon-openmouthedsmile.png" /> Tho it would be difficult depending on how much CSS was generated. Would still be a nice feature. </p>
<p>Either way, the Web Workbench is a tool that can’t be missed. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.philliphaydon.com/2011/11/split-windows-web-workbench-win/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optional Parameters with AttributeRouting</title>
		<link>http://www.philliphaydon.com/2011/11/optional-parameters-with-attributerouting/</link>
		<comments>http://www.philliphaydon.com/2011/11/optional-parameters-with-attributerouting/#comments</comments>
		<pubDate>Sat, 26 Nov 2011 16:38:03 +0000</pubDate>
		<dc:creator>Phillip</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[AttributeRouting]]></category>
		<category><![CDATA[Optional Parameter]]></category>
		<category><![CDATA[Routing]]></category>

		<guid isPermaLink="false">http://www.philliphaydon.com/2011/11/optional-parameters-with-attributerouting/</guid>
		<description><![CDATA[I found a little trick with using Optional Parameters with AttributeRouting, by using standard optional parameters in the action. The documentation says you can add an attributes to specify the defaults, or add ‘=value’ to the parameter name, and I guess that’s a more correct way to generate routes, but you can achieve the same [...]]]></description>
			<content:encoded><![CDATA[<p>I found a little trick with using Optional Parameters with <a href="https://github.com/mccalltd/AttributeRouting/wiki/2.-Usage">AttributeRouting</a>, by using standard optional parameters in the action.</p>
<p>The documentation says you can add an attributes to specify the defaults, or add ‘=value’ to the parameter name, and I guess that’s a more correct way to generate routes, but you can achieve the same affect by making the parameter optional. Like so:</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:af51052c-bccb-4d06-b0bc-9b3bacf140b7" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap">[<span style="color:#2b91af">GET</span>(<span style="color:#a31515">&quot;videos/{?page}&quot;</span>)]<br /> <span style="color:#0000ff">public</span> <span style="color:#2b91af">ActionResult</span> Videos(<span style="color:#0000ff">int</span> page = 1)<br /> {<br />     <span style="color:#0000ff">return</span> View(<span style="color:#a31515">&quot;Result&quot;</span>);<br /> }</div>
</p></div>
</p></div>
</p>
<p>If I browse to the URL: </p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/11/image3.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/11/image_thumb3.png" width="214" height="33" /></a></p>
<p>It uses the default value of 1. </p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/11/image4.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/11/image_thumb4.png" width="380" height="89" /></a></p>
<p>Now when appending a number to the end of the URL:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/11/image5.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/11/image_thumb5.png" width="219" height="35" /></a></p>
<p>It captures the correct value:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/11/image6.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/11/image_thumb6.png" width="390" height="90" /></a></p>
<p>I prefer this method, the optional parameter on the action is more quickly identified, than looking at the attribute to see the defaults. (in my opinion)</p>
<p>Ahh AttributeRouting, how I love you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.philliphaydon.com/2011/11/optional-parameters-with-attributerouting/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Unit of Work with WCF and Autofac</title>
		<link>http://www.philliphaydon.com/2011/11/unit-of-work-with-wcf-and-autofac/</link>
		<comments>http://www.philliphaydon.com/2011/11/unit-of-work-with-wcf-and-autofac/#comments</comments>
		<pubDate>Sat, 05 Nov 2011 15:10:22 +0000</pubDate>
		<dc:creator>Phillip</dc:creator>
				<category><![CDATA[WCF]]></category>
		<category><![CDATA[Autofac]]></category>
		<category><![CDATA[Unit Of Work]]></category>

		<guid isPermaLink="false">http://www.philliphaydon.com/2011/11/unit-of-work-with-wcf-and-autofac/</guid>
		<description><![CDATA[I’ve just spent the last few days trying to find a way to have a Unit of Work with WCF, but it seems no one has a nice clean easy solution. The first, and the only decent solution I found was here: http://ianfnelson.com/archives/2010/04/09/wcf-nhibernate-unit-of-work-endpoint-behavior The problem I found with this solution is that the ICallContextInitializer as [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve just spent the last few days trying to find a way to have a Unit of Work with WCF, but it seems no one has a nice clean easy solution.</p>
<p>The first, and the only decent solution I found was here:</p>
<p><a title="http://ianfnelson.com/archives/2010/04/09/wcf-nhibernate-unit-of-work-endpoint-behavior" href="http://ianfnelson.com/archives/2010/04/09/wcf-nhibernate-unit-of-work-endpoint-behavior" target="_blank">http://ianfnelson.com/archives/2010/04/09/wcf-nhibernate-unit-of-work-endpoint-behavior</a></p>
<p>The problem I found with this solution is that the <em>ICallContextInitializer </em>as well as the <em>EndpointBehavior</em> is only created once. So it would seem all calls to a service would share the same Unit of Work instance. </p>
<p>Maybe Castle Windsor does something fancy and injects a brand new <em>EndpointBehavior</em> every request to a service, but for me, it seemed the <em>ServiceBehavior</em>, <em>EndpointBehavior</em>, and <em>ICallContextInitializer</em> were all created once.</p>
<p>This caused my service to resolve a different instance of IUnitOfWork to what was in the <em>ICallContextInitializer.</em></p>
<h3>Interim Solution 1</h3>
<p>The first solution I came up with was to use Autofac to call Commit on release:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:14ea6e8e-a34f-470a-a40e-e139ea3477d9" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;">builder.RegisterType(<span style="color:#0000ff">typeof</span> (<span style="color:#2b91af">UnitOfWork</span>))<br />         .As(<span style="color:#0000ff">typeof</span> (<span style="color:#2b91af">IUnitOfWork</span>))<br />         .InstancePerLifetimeScope()<br />         .OnRelease(x =&gt;<br />                         {<br />                             ((<span style="color:#2b91af">IUnitOfWork</span>) x).Commit();<br />                         });</div>
</p></div>
</p></div>
<p>It works… <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://www.philliphaydon.com/wp-content/uploads/2011/11/wlEmoticon-smile.png" /> but it seemed like a real hack, so I kept digging.</p>
<p>I posted on <a href="http://stackoverflow.com/questions/7989918/using-a-custom-endpoint-behavior-with-wcf-and-autofac" target="_blank">StackOverflow</a> &amp; <a href="http://groups.google.com/group/autofac/browse_thread/thread/7310498aea634abd" target="_blank">Autofac Google Group</a>, but so far I haven’t had anyone suggest a good solution.</p>
<h3>Solution 2</h3>
<p>The next took a while to come up with. </p>
<p><strong>Note:</strong> <font color="#ff0000"><em>I don’t know if this is an appropriate solution for utilizing a Unit of Work with WCF. It works for me but if there is a better solution I would like to hear it.</em></font></p>
<p>I started by giving all my classes an interface called <em>IService</em>.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d930f4da-f034-4d4b-b1e1-8ed83e9afa5b" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier,Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">interface</span> <span style="color:#2b91af">IService</span><br /> {<br />     <span style="color:#2b91af">IUnitOfWork</span> UnitOfWork { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br /> }</div>
</p></div>
</p></div>
<p>My Service implements this interface:</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d4fd9486-a127-4996-88e7-ea88aef1114f" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'',Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">WasteInventoryQueryService</span> : <span style="color:#2b91af">IWasteInventoryQueryService</span>, <span style="color:#2b91af">IService</span><br /> {<br />     <span style="color:#0000ff">public</span> <span style="color:#2b91af">IUnitOfWork</span> UnitOfWork { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }<br />     <span style="color:#0000ff">public</span> <span style="color:#2b91af">IWasteStockRepository</span> WasteStockRepository { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }</p>
<p>     <span style="color:#0000ff">public</span> WasteInventoryQueryService(<span style="color:#2b91af">IUnitOfWork</span> unitOfWork, <span style="color:#2b91af">IWasteStockRepository</span> wasteStockRepository)<br />     {<br />         UnitOfWork = unitOfWork;<br />         WasteStockRepository = wasteStockRepository;<br />     }</p>
<p>     &#8230;<br /> }</div>
</p></div>
</p></div>
</p>
<p>Next I created some behaviours similar to the linked article.</p>
<p>Since finding that the ServiceBehavior, EndpointBehavior and ICallContextInitializer all are created once, I started at the ServiceBehavior. </p>
<p>I created a class called EndpointResolverServiceBehavior, it’s purpose is to inject all the endpoint behaviours I create.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b0780a55-e236-46f5-8932-bc97bff59a8a" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">EndpointResolverServiceBehavior</span> : <span style="color:#2b91af">IServiceBehavior</span><br /> {<br />     <span style="color:#0000ff">protected</span> <span style="color:#2b91af">IEnumerable</span>&lt;<span style="color:#2b91af">IEndpointBehavior</span>&gt; EndpointBehaviors { <span style="color:#0000ff">get</span>; <span style="color:#0000ff">set</span>; }</p>
<p>     <span style="color:#0000ff">public</span> EndpointResolverServiceBehavior(<span style="color:#2b91af">IEnumerable</span>&lt;<span style="color:#2b91af">IEndpointBehavior</span>&gt; endpointBehaviors)<br />     {<br />         EndpointBehaviors = endpointBehaviors;<br />     }</p>
<p> <span style="color:#0000ff">    #region</span> Implementation of IServiceBehavior</p>
<p>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">void</span> Validate(<span style="color:#2b91af">ServiceDescription</span> serviceDescription, <span style="color:#2b91af">ServiceHostBase</span> serviceHostBase)<br />     {<br />     }</p>
<p>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">void</span> AddBindingParameters(<span style="color:#2b91af">ServiceDescription</span> serviceDescription, <br />         <span style="color:#2b91af">ServiceHostBase</span> serviceHostBase, <br />         <span style="color:#2b91af">Collection</span>&lt;<span style="color:#2b91af">ServiceEndpoint</span>&gt; endpoints, <br />         <span style="color:#2b91af">BindingParameterCollection</span> bindingParameters)<br />     {<br />     }</p>
<p>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">void</span> ApplyDispatchBehavior(<span style="color:#2b91af">ServiceDescription</span> serviceDescription, <span style="color:#2b91af">ServiceHostBase</span> serviceHostBase)<br />     {<br />         <span style="color:#0000ff">foreach</span> (<span style="color:#0000ff">var</span> endpoint <span style="color:#0000ff">in</span> serviceDescription.Endpoints)<br />         {<br />             <span style="color:#0000ff">foreach</span> (<span style="color:#0000ff">var</span> endpointBehavior <span style="color:#0000ff">in</span> EndpointBehaviors)<br />             {<br />                 endpoint.Behaviors.Add(endpointBehavior);<br />             }<br />         }<br />     }</p>
<p> <span style="color:#0000ff">    #endregion</span><br /> }</div>
</p></div>
</p></div>
<p>Next I created an EndpointBehavior called UnitOfWorkEndpointBehavior, it’s purpose is to add the ICallContextInitializer instance.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4ab965c3-1746-40d4-b005-01a72f717606" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">UnitOfWorkEndpointBehavior</span> : <span style="color:#2b91af">IEndpointBehavior</span><br /> {<br />     <span style="color:#0000ff">public</span> <span style="color:#0000ff">void</span> AddBindingParameters(<span style="color:#2b91af">ServiceEndpoint</span> endpoint, <span style="color:#2b91af">BindingParameterCollection</span> bindingParameters)<br />     {<br />     }</p>
<p>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">void</span> ApplyClientBehavior(<span style="color:#2b91af">ServiceEndpoint</span> endpoint, <span style="color:#2b91af">ClientRuntime</span> clientRuntime)<br />     {<br />     }</p>
<p>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">void</span> ApplyDispatchBehavior(<span style="color:#2b91af">ServiceEndpoint</span> endpoint, <span style="color:#2b91af">EndpointDispatcher</span> endpointDispatcher)<br />     {<br />         <span style="color:#0000ff">foreach</span> (<span style="color:#2b91af">DispatchOperation</span> operation <span style="color:#0000ff">in</span> endpointDispatcher.DispatchRuntime.Operations)<br />         {<br />             operation.CallContextInitializers.Add(<span style="color:#0000ff">new</span> <span style="color:#2b91af">UnitOfWorkCallContextInitializer</span>());<br />         }<br />     }</p>
<p>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">void</span> Validate(<span style="color:#2b91af">ServiceEndpoint</span> endpoint)<br />     {<br />     }<br /> }</div>
</p></div>
</p></div>
<p>And then is the ICallContextInitializer. </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d63640b6-7c52-43b4-b244-dd2f1b4399ab" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">UnitOfWorkCallContextInitializer</span> : <span style="color:#2b91af">ICallContextInitializer</span><br /> {<br />     <span style="color:#0000ff">private</span> <span style="color:#2b91af">PropertyInfo</span> _userObjectInfo;<br />     <span style="color:#0000ff">private</span> <span style="color:#0000ff">readonly</span> <span style="color:#2b91af">BindingFlags</span> _flags = <span style="color:#2b91af">BindingFlags</span>.NonPublic | <span style="color:#2b91af">BindingFlags</span>.Instance;</p>
<p>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">object</span> BeforeInvoke(<span style="color:#2b91af">InstanceContext</span> instanceContext, <span style="color:#2b91af">IClientChannel</span> channel, <span style="color:#2b91af">Message</span> message)<br />     {<br />         <span style="color:#0000ff">if</span> (_userObjectInfo == <span style="color:#0000ff">null</span>)<br />             _userObjectInfo = instanceContext.GetType()<br />                                                 .GetProperty(<span style="color:#a31515">&quot;UserObject&quot;</span>, _flags);<br />             <br />         <span style="color:#0000ff">return</span> _userObjectInfo.GetValue(instanceContext, <span style="color:#0000ff">null</span>) <span style="color:#0000ff">as</span> <span style="color:#2b91af">IService</span>;<br />     }</p>
<p>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">void</span> AfterInvoke(<span style="color:#0000ff">object</span> correlationState)<br />     {<br />         <span style="color:#0000ff">var</span> uow = correlationState <span style="color:#0000ff">as</span> <span style="color:#2b91af">IService</span>;</p>
<p>         <span style="color:#0000ff">if</span> (uow != <span style="color:#0000ff">null</span>)<br />             uow.UnitOfWork.Commit();<br />     }<br /> }</div>
</p></div>
</p></div>
<p>While debugging I found out that the InstanceContext has a private property which has the current service attached to it:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/11/image.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/11/image_thumb.png" width="639" height="32" /></a></p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/11/image1.png" target="_blank"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/11/image_thumb1.png" width="242" height="127" /></a></p>
<p><em>(click the image for a larger view)</em></p>
<p>So I reflected the property and casted it to an IService, and return the result. When the service has been invoked, the result passed out of the ‘BeforeInvoke’ method, is passed into the ‘AfterInvoke’.</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/11/image2.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/11/image_thumb2.png" width="626" height="210" /></a></p>
<p>So basically I return the result from the BeforeInvoke which is passed into the AfterInvoke. Then I attempt to cast it to an IService again.</p>
<p>If the cast is successful, then I can call Commit on my UnitOfWork.</p>
<p>The last piece is to wire up the Behavior with Autofac.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d0ce48a9-f6af-478d-a1b7-7ceb8be6b2c0" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;">builder.RegisterType(<span style="color:#0000ff">typeof</span>(<span style="color:#2b91af">UnitOfWorkEndpointBehavior</span>)).As(<span style="color:#0000ff">typeof</span>(<span style="color:#2b91af">IEndpointBehavior</span>));<br /> builder.RegisterType(<span style="color:#0000ff">typeof</span>(<span style="color:#2b91af">EndpointResolverServiceBehavior</span>)).As(<span style="color:#0000ff">typeof</span>(<span style="color:#2b91af">IServiceBehavior</span>));</p>
<p> Container = builder.Build();</p>
<p> <span style="color:#2b91af">AutofacHostFactory</span>.Container = Container;<br /> <span style="color:#2b91af">AutofacHostFactory</span>.HostConfigurationAction =<br />     host =&gt;<br />     {<br />         host.Description.Behaviors.Add(Container.Resolve&lt;<span style="color:#2b91af">IServiceBehavior</span>&gt;());<br />     };</div>
</p></div>
</p></div>
<p>And it’s done. I have a working Unit of Work, that is injected into my Service and Committed after the service has been invoked.</p>
<p>The only down-side I see to all of this, is that if an exception is thrown that I don’t capture, then the UoW will still be committed regardless. </p>
<p>If anyone has any better solutions, let me know! <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://www.philliphaydon.com/wp-content/uploads/2011/11/wlEmoticon-smile.png" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.philliphaydon.com/2011/11/unit-of-work-with-wcf-and-autofac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Phone, Windows Live and MSN</title>
		<link>http://www.philliphaydon.com/2011/11/windows-phone-windows-live-and-msn/</link>
		<comments>http://www.philliphaydon.com/2011/11/windows-phone-windows-live-and-msn/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 12:00:28 +0000</pubDate>
		<dc:creator>Phillip</dc:creator>
				<category><![CDATA[Rant]]></category>
		<category><![CDATA[Windows Phone 7]]></category>

		<guid isPermaLink="false">http://www.philliphaydon.com/?p=247</guid>
		<description><![CDATA[Windows Phone 7.5 has been getting some awesome reviews, and rightly so. The thing is amazing. I really think Microsoft has begun leading the way for the mobile platform. But I&#8217;m highly pissed off with the Windows Phone team. Why? Because to use MSN, your msn contacts must be associated with the first live account [...]]]></description>
			<content:encoded><![CDATA[<p>Windows Phone 7.5 has been getting some awesome reviews, and rightly so. The thing is amazing. I really think Microsoft has begun leading the way for the mobile platform.</p>
<p>But I&#8217;m highly pissed off with the Windows Phone team. Why? <strong><em>Because to use MSN, your msn contacts must be associated with the first live account you register to the phone.</em></strong></p>
<p>I don&#8217;t even know what to say about this, it&#8217;s so silly. I understand that it might get confusing to allow multiple Facebook accounts, multiple Windows Live accounts, etc.</p>
<p>But could they not allow you to choose which account MSN contacts are associated to?</p>
<p>When I first setup my phone I didn&#8217;t use the Windows Live account I use for MSN (my Hotmail) since it&#8217;s existed since 1997, it&#8217;s got 100&#8242;s of contacts I don&#8217;t want in my phone-book, a lot of MSN contacts exist from work, or playing online games, or from forums etc. So I used the Windows Live account that I use for MSDN. I added all my contacts and everything was great, (after I imported all my contacts from outlook into Windows Live Contacts)</p>
<p>I attached my Facebook account, went to People &gt; Settings &gt; Filter Contacts, and turned off Facebook so they do not show in my normal contacts list. This allows me to have normal phone users, but see the Facebook users on the Messaging list.</p>
<p>Now I want to show MSN contacts, so I load up the next Windows Live account, it loads all my contacts, but when I go to messaging, I get NOTHING. No MSN users at all.</p>
<p>On my second Windows Phone (yes I have two) I reformatted it, and signed it up on my Hotmail Windows Live account, and what do I see? All my MSN contacts.</p>
<p>Ok so the team didn&#8217;t give us the option to select which Live account we can use for MSN&#8230; So I went to download <a href="http://www.windowsphone.com/en-GB/apps/7c59963c-ddae-e011-a53c-78e7d1fa76f8">IM+</a></p>
<p><strong>DEAD END</strong></p>
<blockquote><p>ATTENTION MSN/WLM users! MSN/WLM is not supported in 1.7 version of IM+ due to Microsoft Marketplace request. If you would like to continue using MSN/WLM in IM+, do not update to 1.7 version from version 1.2. We will continue working on this situation with Microsoft.</p></blockquote>
<p>WTF&#8230; So not only can I not use MSN on my phone natively. The team has blocked anyone else from providing the feature in their own applications&#8230;</p>
<p>That&#8217;s not fair at all.</p>
<p>Microsoft should be ashamed.</p>
<p>So as it stands, if you don&#8217;t use your MSN account as your Windows Phone account, you can&#8217;t use MSN.</p>
<p>Microsoft is definitely leading the way in Mobile platform, but they massively screwed up MSN for many users.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.philliphaydon.com/2011/11/windows-phone-windows-live-and-msn/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RavenDB &#8211; Changing the Lo on the HiLo Generator</title>
		<link>http://www.philliphaydon.com/2011/10/ravendb-changing-the-lo-on-the-hilo-generator/</link>
		<comments>http://www.philliphaydon.com/2011/10/ravendb-changing-the-lo-on-the-hilo-generator/#comments</comments>
		<pubDate>Sun, 23 Oct 2011 14:38:47 +0000</pubDate>
		<dc:creator>Phillip</dc:creator>
				<category><![CDATA[RavenDB]]></category>
		<category><![CDATA[Capacity]]></category>
		<category><![CDATA[Generator]]></category>
		<category><![CDATA[HiLo]]></category>
		<category><![CDATA[Identity]]></category>

		<guid isPermaLink="false">http://www.philliphaydon.com/2011/10/ravendb-changing-the-lo-on-the-hilo-generator/</guid>
		<description><![CDATA[Well I’m currently learning RavenDB, it’s awesome! But I noticed when I put data in, all the Id’s generated every time I ran up my application to test were: 1, 2, 3, 4, 5… 1024, 1025, 1026, 1027, 1028… 2048, 2049, 2050, 2051, 2052… This would be fine after the app is deployed since I [...]]]></description>
			<content:encoded><![CDATA[<p>Well I’m currently learning RavenDB, it’s awesome! But I noticed when I put data in, all the Id’s generated every time I ran up my application to test were:</p>
<p>1, 2, 3, 4, 5…</p>
<p>1024, 1025, 1026, 1027, 1028…</p>
<p>2048, 2049, 2050, 2051, 2052…</p>
<p>This would be fine after the app is deployed since I wouldn’t be restarting it over and over and over, but during development I personally find it annoying that the numbers jump so high.</p>
<p>Fortunately I figured out a way. <em>(which about an hour later I found on Google Groups, granted I had to use a different keyword to find it)</em></p>
<p>Basically you just need to create a new instance of the MultiTypeHiLoKeyGenerator class, passing in the arguments and assigning it to the document store:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d3c80e90-6b94-435f-aac1-130619bcee2b" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: ''Courier New'', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">var</span> documentStore = <span style="color:#0000ff">new</span> <span style="color:#2b91af">DocumentStore</span> { Url = <span style="color:#a31515">&quot;http://localhost:12321/&quot;</span> };<br /> documentStore.Initialize();</p>
<p> <span style="color:#0000ff">var</span> generator = <span style="color:#0000ff">new</span> <span style="color:#2b91af">MultiTypeHiLoKeyGenerator</span>(documentStore, 10);<br /> documentStore.Conventions.DocumentKeyGenerator = <br />     entity =&gt; generator.GenerateDocumentKey(documentStore.Conventions, entity);</p>
<p> <span style="color:#0000ff">using</span> (<span style="color:#0000ff">var</span> session = documentStore.OpenSession())<br /> {<br />     session.Store(<span style="color:#0000ff">new</span> <span style="color:#2b91af">Project</span>() { Title = <span style="color:#a31515">&quot;Hello World&quot;</span> });<br />     session.SaveChanges();<br /> }</div>
</p></div>
</p></div>
<p>So running up my app once:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/10/image.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/10/image_thumb.png" width="334" height="201" /></a></p>
<p>And again:</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/10/image1.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/10/image_thumb1.png" width="394" height="189" /></a></p>
<p>Now the identity only increases every time the app restarts. And to show it generates more than 1 number…</p>
<p><a href="http://www.philliphaydon.com/wp-content/uploads/2011/10/image2.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.philliphaydon.com/wp-content/uploads/2011/10/image_thumb2.png" width="568" height="207" /></a></p>
<p>It took a while of hunting on the net, but it turns out Googling &amp; Binging, or searching(<em>StackOverflow/Google Groups</em>) for the keyword ‘<strong>Lo</strong>’ doesn’t work, the argument is ‘<strong>capacity</strong>’ and searching for that on Google Groups lead me here:</p>
<p><a title="http://groups.google.com/group/ravendb/browse_thread/thread/95a5b33a5d30eb71/a5197e2e01376e65?lnk=gst&amp;q=capacity#a5197e2e01376e65" href="http://groups.google.com/group/ravendb/browse_thread/thread/95a5b33a5d30eb71/a5197e2e01376e65?lnk=gst&amp;q=capacity#a5197e2e01376e65">http://groups.google.com/group/ravendb/&#8230;..q=capacity</a></p>
<p>Hopefully someone else finds this useful <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://www.philliphaydon.com/wp-content/uploads/2011/10/wlEmoticon-smile.png" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.philliphaydon.com/2011/10/ravendb-changing-the-lo-on-the-hilo-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

