<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Jonel Rienton's Blog</title><link>https://weblogs.asp.net:443/jonelrienton/</link><description>Sitecore, SharePoint, WF, WCF, ASP.Net, ADO.Net, LINQ, ASP.Net MVC</description><item><title>Watching Green Day and discovering Sitecore, priceless.</title><link>https://weblogs.asp.net:443/jonelrienton/watching-greenday-and-discovering-sitecore-priceless</link><description>&lt;p&gt;I’m feeling inspired and I’d like to share a technique we’ve implemented in Sitecore to address a URL mapping from our legacy site that we wanted to carry over to the new beautiful &lt;a href="http://www.littelfuse.com" target="_blank"&gt;Littelfuse.com&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The challenge is to carry over all of our series URLs that have been published in our datasheets, we currently have a lot of series and having to create a manual mapping for those could be really tedious. It has the format of &lt;a href="http://www.littelfuse.com/series/series-name.html"&gt;http://www.littelfuse.com/series/series-name.html&lt;/a&gt;, for instance, &lt;a href="http://www.littelfuse.com/series/flnr.html"&gt;http://www.littelfuse.com/series/flnr.html&lt;/a&gt;. It would have been easier if we have our information architecture defined like this but that would have been too easy. &lt;/p&gt;  &lt;p&gt;I took a solution that is 2-fold. First, I need to create a URL rewrite rule using the IIS URL Rewrite Module 2.0. Secondly, we need to implement a handler that will take care of the actual lookup of the actual series. It will be amazing after we’ve gone over the details.&lt;/p&gt;  &lt;p&gt;Let’s start with the URL rewrite. Create a new blank rule, you can name it with anything you wish. The key part here to talk about is the Pattern and the Action groups. The Pattern is nothing but regex. Basically, I’m telling it to match the regex I have defined. In the Action group, I am telling it what to do, in this case, rewrite to the redirect.aspx webform. In this implementation, I will be using Rewrite instead of redirect so the URL sticks in the browser. If you opt to use Redirect, then the URL bar will display the new URL our webform will redirect to.&lt;/p&gt;  &lt;p&gt;Let me explain one small thing, the (\w+) in my Pattern group’s regex, will actually translate to {R:1} in my Action’s group. This is where the magic begins.&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/Media/image_5CC12AF7.png"&gt;&lt;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="https://aspblogs.blob.core.windows.net/media/jonelrienton/Media/image_thumb_09D617C6.png" width="676" height="571" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now let’s see what our Redirect.aspx contains. Remember our {R:1} above which becomes the query string variable s? This are basic .Net code. The only thing that you will probably ask is the LFSearch class. It’s our own implementation of addressing finding items by using a field search, we supply the fieldname, the value of the field, the template name of the item we are after, and the value of true or false if we want to do an exact search, or not.&lt;/p&gt;  &lt;p&gt;If eureka, then redirect to that item’s Path (Url). If not, tell the user tough luck, here’s the 404 page as a consolation.&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/Media/image_3037FB11.png"&gt;&lt;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="https://aspblogs.blob.core.windows.net/media/jonelrienton/Media/image_thumb_0FB0BB5F.png" width="653" height="311" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Amazing, ain’t it?&lt;/p&gt;</description><pubDate>Fri, 14 Dec 2012 01:22:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/jonelrienton/watching-greenday-and-discovering-sitecore-priceless</guid><category>.Net</category><category>ASP.NET</category><category>LINQ</category><category>Sitecore</category><category>Visual Studio.Net</category></item><item><title>Microsoft opens up Team Foundation Service (TFS) for free (for now)</title><link>https://weblogs.asp.net:443/jonelrienton/microsoft-opens-up-team-foundation-service-tfs-for-free-for-now</link><description>I have been evaluating Microsoft's TFS (service) for almost a couple of months now. It allows you to host your solution in the cloud with lets you add up to 5 users. Build is currently in preview and will be included in the Free Plan on a limited basis.
&lt;BR/&gt;&lt;br/&gt;
Go to &lt;a href="https://tfs.visualstudio.com"&gt;https://tfs.visualstudio.com&lt;/a&gt; to check it out.</description><pubDate>Sun, 18 Nov 2012 21:48:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/jonelrienton/microsoft-opens-up-team-foundation-service-tfs-for-free-for-now</guid><category>.Net</category><category>Visual Studio.Net</category></item><item><title>Sitecore Item Web API and Json.Net Test Drive (Part II –Strongly Typed)</title><link>https://weblogs.asp.net:443/jonelrienton/sitecore-item-web-api-and-json-net-test-drive-part-ii</link><description>&lt;p&gt;In the &lt;a href="http://weblogs.asp.net/jonelrienton/archive/2012/11/08/sitecore-item-web-api-and-json-net-test-drive.aspx"&gt;earlier post&lt;/a&gt; I did related to this topic, I have talked about using Json.Net to consume the result of &lt;a href="http://www.sitecore.net" target="_blank"&gt;Sitecore&lt;/a&gt; Item Web API. In that post, I have used the keyword dynamic to express my intention of consuming the returned json of the API.&lt;/p&gt;  &lt;p&gt;In this article, I will create some useful classes to write our implementation of consuming the API using strongly-typed. We will start of with the Record class which will hold the top most elements the API will present us.&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/Media/image_441E4FFA.png"&gt;&lt;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="Record class" border="0" alt="Record class" src="https://aspblogs.blob.core.windows.net/media/jonelrienton/Media/image_thumb_2EC09A92.png" width="313" height="150" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Pretty straight forward class. It has 2 properties to hold the statuscode and the result elements. If you intend to use a different property name in your class from the json property, you can do so by passing a string literal of the json property name to the JsonProperty attribute and name your class property differently.&lt;/p&gt;  &lt;p&gt;If you look at the &lt;a href="http://weblogs.asp.net/jonelrienton/archive/2012/11/08/sitecore-item-web-api-and-json-net-test-drive.aspx"&gt;earlier post&lt;/a&gt;, you will notice that the API returns an array of items that contains all of the &lt;a href="http://www.sitecore.net" target="_blank"&gt;Sitecore&lt;/a&gt; content item or items and stores them under the result-&amp;gt;items array element. To be able to map that array of items, we have to write a collection property and decorate that with the JsonProperty attribute.&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/Media/image_2F38517A.png"&gt;&lt;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="Result class" border="0" alt="Result class" src="https://aspblogs.blob.core.windows.net/media/jonelrienton/Media/image_thumb_0EB111C8.png" width="336" height="179" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The JsonItem class is a simple class which will map to the corresponding item property contained in the array. If you notice, these properties are just the basic &lt;a href="http://www.sitecore.net" target="_blank"&gt;Sitecore&lt;/a&gt; fields.&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/Media/image_7C5CC712.png"&gt;&lt;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="JsonItem class" border="0" alt="JsonItem class" src="https://aspblogs.blob.core.windows.net/media/jonelrienton/Media/image_thumb_62F4C3D8.png" width="308" height="277" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;And here’s the main portion of this post that will binds them all together.&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/Media/image_349B3E2B.png"&gt;&lt;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="Main" border="0" alt="Main" src="https://aspblogs.blob.core.windows.net/media/jonelrienton/Media/image_thumb_7B182E33.png" width="707" height="380" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;And here’s the output of this code.&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/Media/image_41951E3C.png"&gt;&lt;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="Output" border="0" alt="Output" src="https://aspblogs.blob.core.windows.net/media/jonelrienton/Media/image_thumb_67F70187.png" width="677" height="342" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In closing, the same result can be achieved using the dynamic keyword or defining classes to map the json propery returned by the &lt;a href="http://weblogs.asp.net/jonelrienton/archive/2012/11/08/sitecore-item-web-api-and-json-net-test-drive.aspx" target="_blank"&gt;Sitecore Item Web API&lt;/a&gt;. With a little bit more of coding, you can take advantage of power of strongly-typed solution.&lt;/p&gt;  &lt;p&gt;Have a good week ahead of you.&lt;/p&gt;</description><pubDate>Sun, 18 Nov 2012 21:30:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/jonelrienton/sitecore-item-web-api-and-json-net-test-drive-part-ii</guid><category>.Net</category><category>Sitecore</category><category>Visual Studio.Net</category></item><item><title>Sitecore Item Web API and Json.Net Test Drive</title><link>https://weblogs.asp.net:443/jonelrienton/sitecore-item-web-api-and-json-net-test-drive</link><description>&lt;p&gt;Sitecore recently released it’s Item Web API product and I think it will be good for the community to see some sample application. I plan a to do a 3 series blog iteration in the coming weeks, this, being the first one.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://weblogs.asp.net/jonelrienton/archive/2012/11/08/sitecore-item-web-api-and-json-net-test-drive.aspx"&gt;Sitecore Item Web API and Json.Net Test Drive&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/jonelrienton/archive/2012/11/18/sitecore-item-web-api-and-json-net-test-drive-part-ii.aspx"&gt;Sitecore Item Web API and Json.Net Test Drive (Part II – Strongly Typed)&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Sitecore Item Web API and MonoTouch (iOS development), specifically MonoTouch.Dialog – awesome, awesome framework. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Before moving on, the assumption is you have already installed and configured Sitecore’s Item Web API in your development environment. I can probably cover that as well on a separate blog. It’s really simple, really.&lt;/p&gt;  &lt;p&gt;So now that you have Sitecore’s Item Web API installed, you are probably asking yourself what does this new tool provide? In a nutshell, it provides you 3 things:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Allows client to get Sitecore items based on ID or query. For now, based on my evaluation, it supports Sitecore query and Sitecore fast query. The limitation I saw initially was it does not allow me to include query filters like [@@templatename=’Product’]. &lt;/li&gt;    &lt;li&gt;Allows item manipulation (add/update/delete). This is done via the different Http verbs. &lt;/li&gt;    &lt;li&gt;Allows media uploads. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Now that we got that out of the way, let’s look at the existing code below. &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Lines 3 to 10 are just basic variable declarations. It gets the values from the app.config this case. &lt;/li&gt;    &lt;li&gt;Lines 12 to 19 just sets the string variable request based on the value of the query. &lt;/li&gt;    &lt;li&gt;Line 21 downloads the actual request &lt;/li&gt;    &lt;li&gt;Line 23 parses the returned json string using &lt;a href="http://json.codeplex.com/" target="_blank"&gt;Json.Net&lt;/a&gt;. Note the usage of the dynamic keyword. Very powerful stuff. &lt;/li&gt;    &lt;li&gt;If you look at the returned json string, you can see that it contained the items array inside the result. &lt;/li&gt; &lt;/ol&gt;  &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-size: 10pt; border-top: #000080 1px solid; font-weight: bold; border-right: #000080 1px solid; padding-top: 2px"&gt;Code Snippet&lt;/div&gt;  &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt;   &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt;     &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt;       &lt;li&gt;&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] args) &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; client = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;WebClient&lt;/span&gt;(); &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160; &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; apiUrl = getConfiguration(&lt;span style="color: #a31515"&gt;&amp;quot;apiUrl&amp;quot;&lt;/span&gt;); &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; query = getConfiguration(&lt;span style="color: #a31515"&gt;&amp;quot;query&amp;quot;&lt;/span&gt;); &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; sc_itemid = getConfiguration(&lt;span style="color: #a31515"&gt;&amp;quot;sc_itemid&amp;quot;&lt;/span&gt;); &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; apiParam = getConfiguration(&lt;span style="color: #a31515"&gt;&amp;quot;apiParam&amp;quot;&lt;/span&gt;); &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; payLoad = getConfiguration(&lt;span style="color: #a31515"&gt;&amp;quot;payload&amp;quot;&lt;/span&gt;); &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; request = &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;; &lt;/li&gt;        &lt;li&gt;&amp;#160; &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (apiParam.Equals(&lt;span style="color: #a31515"&gt;&amp;quot;query&amp;quot;&lt;/span&gt;,&lt;span style="color: #2b91af"&gt;StringComparison&lt;/span&gt;.OrdinalIgnoreCase)) &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; request = &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;{0}?{1}&amp;amp;{2}&amp;quot;&lt;/span&gt;, apiUrl, query, payLoad); &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (apiParam.Equals(&lt;span style="color: #a31515"&gt;&amp;quot;id&amp;quot;&lt;/span&gt;,&lt;span style="color: #2b91af"&gt;StringComparison&lt;/span&gt;.OrdinalIgnoreCase)) &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; request = &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;{0}?{1}&amp;amp;{2}&amp;quot;&lt;/span&gt;, apiUrl, sc_itemid, payLoad); &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160; &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; apiResponse = client.DownloadString(request); &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160; &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;dynamic&lt;/span&gt; jsonResponse = &lt;span style="color: #2b91af"&gt;JObject&lt;/span&gt;.Parse(apiResponse); &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160; &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;null&lt;/span&gt;!=jsonResponse &amp;amp;&amp;amp; jsonResponse.statusCode==&lt;span style="color: #a31515"&gt;&amp;quot;200&amp;quot;&lt;/span&gt;) &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;Status code:&amp;quot;&lt;/span&gt; + jsonResponse.statusCode); &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;Total Count:&amp;quot;&lt;/span&gt; + jsonResponse.result.totalCount); &lt;/li&gt;        &lt;li&gt;&amp;#160; &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; item &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; jsonResponse.result.items) &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(item.DisplayName + &lt;span style="color: #a31515"&gt;&amp;quot;: &amp;quot;&lt;/span&gt; + item.Path); &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/li&gt;        &lt;li&gt;&amp;#160; &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;Done.&amp;quot;&lt;/span&gt;); &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.ReadLine(); &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/li&gt;        &lt;li&gt;&amp;#160; &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; getConfiguration(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; p) &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ConfigurationManager&lt;/span&gt;.AppSettings[p]; &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/li&gt;     &lt;/ol&gt;   &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Here’s a copy of the returned json. Viewed using Chrome and Pretty Json.&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/Media/image_746C7C02.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="https://aspblogs.blob.core.windows.net/media/jonelrienton/Media/image_thumb_3EF3B9DD.png" width="535" height="661" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Here’s a copy of the app.config&lt;/p&gt;  &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt;   &lt;div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px"&gt;App.config&lt;/div&gt;    &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt;     &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt;       &lt;li&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #a31515"&gt;xml&lt;/span&gt;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;version&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;1.0&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;encoding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;utf-8&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt; ?&amp;gt;&lt;/span&gt; &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;configuration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;appSettings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;apiUrl&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;http://sitecore.local/-/item/v1&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&lt;/span&gt;&lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;query&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;query=/sitecore/content/home/products/*&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;/li&gt;        &lt;li&gt;&amp;#160; &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&amp;lt;!--&lt;/span&gt;&lt;span style="color: #008000"&gt; &lt;/span&gt;&lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #008000"&gt;apiParam: values could be query or id&lt;/span&gt; &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #008000"&gt;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;--&amp;gt;&lt;/span&gt; &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;apiParam&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;qUery&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&lt;/span&gt;&lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;sc_itemid&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;sc_itemid={F29FBDBA-8DA7-4EE7-8114-07ECC25F42CF}&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&lt;/span&gt;&lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&amp;lt;!--&lt;/span&gt;&lt;span style="color: #008000"&gt; &lt;/span&gt;&lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #008000"&gt;Payload: values could be min, content, or full&lt;/span&gt; &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #008000"&gt;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;--&amp;gt;&lt;/span&gt; &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;payload&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;payload=min&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&lt;/span&gt;&lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&amp;lt;!--&lt;/span&gt;&lt;span style="color: #008000"&gt; &amp;lt;add key=&amp;quot;fields&amp;quot; value=&amp;quot;&amp;quot;/&amp;gt; &lt;/span&gt;&lt;span style="color: #0000ff"&gt;--&amp;gt;&lt;/span&gt; &lt;/li&gt;        &lt;li&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;appSettings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;/li&gt;        &lt;li style="background: #f3f3f3"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;configuration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;/li&gt;     &lt;/ol&gt;   &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;In closing, I’ve only touched the surface of Sitecore’s Item Web API. I’m sure the next releases will build upon this new framework and make it more awesome.&lt;/p&gt;</description><pubDate>Fri, 09 Nov 2012 03:00:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/jonelrienton/sitecore-item-web-api-and-json-net-test-drive</guid><category>.Net</category><category>Sitecore</category><category>Visual Studio.Net</category></item><item><title>Viewing Sitecore log in real time</title><link>https://weblogs.asp.net:443/jonelrienton/viewing-sitecore-log-in-real-time</link><description>
&lt;p&gt;It's been almost a year since I've been Sitecore certified and I've learned so much by reading documentations, reviewing existing code, reading best in class blogs and gathering peers recommendations. In my initial months with Sitecore, I found out about the log viewer which basically allows us to view the current and previous logs of Sitecore. Pretty handy if you are troubleshooting some issues or using the logs to see what's happening with your application/website.&amp;nbsp; One of the drawbacks I noticed right away is I have to refresh the log every time to see the latest additions. &lt;/p&gt;
&lt;p&gt;Coming from a unix background, I am familiar with a command line tool called Tail. Fortunately, there's a Windows version of tail and even better with a GUI interface. I highly recommend this tool as it provides you real time information in your current Sitecore log. You can download the application from the &lt;a href="http://tailforwin32.sourceforge.net/" mce_href="http://tailforwin32.sourceforge.net/"&gt;Tail for Win32&lt;/a&gt; website. &lt;br&gt;&lt;/p&gt;
</description><pubDate>Sun, 01 Jul 2012 00:26:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/jonelrienton/viewing-sitecore-log-in-real-time</guid><category>Sitecore</category></item><item><title>Sitecore fast query not returning items when searching for item names issue and how to fix</title><link>https://weblogs.asp.net:443/jonelrienton/sitecore-fast-query-not-returning-items-when-searching-for-item-names-issue-and-how-to-fix</link><description>&lt;p&gt;&amp;nbsp;I've recently hit a snag while using Sitecore's fast query. To begin with, I first noticed the issue when one of my colleagues reported that the upload application we have recently developed is not working. The upload application is supposed to add children to items that already existed. It turns out that the issue was the fast query I have written was not finding the parent item those children are supposed to be loaded under. &lt;/p&gt;&lt;p&gt;&amp;nbsp;Here's a look of the query I was using:&lt;/p&gt;&lt;p&gt;fast:/sitecore/content/home/products//X7500&lt;/p&gt;&lt;p&gt;I know this parent item exists as I can view it in the content editor. &lt;br&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;After a few tries using the XPath Builder, Sitecore Rocks Query Analyzer and its own XPath builder, I have concluded that this might be something I can spend hours spinning my wheels but not be able to solve. So I turned to Sitecore support. After a day of corresponding in the Sitecore support portal, the engineer came back and told me that I need to run the Clean Database interface and so I did.&lt;/p&gt;&lt;p&gt;Now, this Clean Database interface is one of those that are not well documented (or I might not have done my home work or research well enough). It turns out that when you run this database clean up, the time it will take depends on the size of your master database. In my case, it was a little under an hour. Here's another interesting thought, it kept on timing out on my first couple of tries. Now since this is a background process, I decided to close the modal window after I have&amp;nbsp; started the process and tail my logs to see what's happening. Sitecore logs stated that the Database Clean up has started and after a few minutes it stated that the job completed (no error message though) so I thought everything went well. &lt;/p&gt;&lt;p&gt;&amp;nbsp;When I tried the same fast query above, it still didn't work. So I did some research and find out that the DefaultSqlTimeout setting in the web.config is initially set to 5 minutes by default. After adjusting that value I re-run the Clean Database interface and let the modal window stay and this time it completed with no issues and my fast query is now returning the parent items which were not being found earlier.&lt;/p&gt;&lt;p&gt;One thing I recall about those parent items that were not being found, we actually move that item from a staging website to the production website in the same Sitecore installation. I'm not certain if that was the root cause but it might have contributed to it. &lt;/p&gt;</description><pubDate>Sat, 30 Jun 2012 03:03:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/jonelrienton/sitecore-fast-query-not-returning-items-when-searching-for-item-names-issue-and-how-to-fix</guid><category>Sitecore</category></item><item><title>FirstOrDefault to the rescue</title><link>https://weblogs.asp.net:443/jonelrienton/firstordefault-to-the-rescue</link><description>&lt;p&gt;I have been tinkering with LINQ for quite a bit now and I came across a trivial question about how does LINQ return an entity. I'm going to start off by sharing you a very simple example just to illustrate.&amp;#160; To begin, I'll create a Contact table:&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_4.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="203" alt="image" src="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_thumb_1.png" width="504" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Very simple stuff, I start by creating a schema, create the table and start inserting 3 records to it. The next thing I'm going to do is create a solution using Visual Studio 2008. &lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_6.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="342" alt="image" src="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_thumb_2.png" width="504" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I have renamed the default Class1.cs to ContactDirector.cs. I will then add a LINQ to SQL Class and call it Contact.dbml. VS in turn will create a class for me called ContactDataContext behind the scenes. This class inherits from System.Data.Linq.DataContext. &lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_8.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="306" alt="image" src="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_thumb_3.png" width="504" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;After VS has done its code generation, I'm presented with the LINQ designer. I will go ahead and drag my newly created Contact table to the designer.&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_10.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="615" alt="image" src="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_thumb_4.png" width="504" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Ok, we're halfway there. I will now start writing a few code to go back to our initial topic.&amp;#160; At first, I'll start using the very basic way of getting a contact back.&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_12.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="440" alt="image" src="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_thumb_5.png" width="504" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I know, I know it's not so elegant at all. But let me generate some unit test from this and I'll show you that indeed this works. But before I do that, I have to override a couple of members of the Contact class. The Equals and the GetHashCode methods. I have to implement a custom logic to compare one contact to another for my testing.&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_14.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="484" alt="image" src="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_thumb_6.png" width="490" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Here's my unit test auto-generated by VS, I just added the value for the contactId and the expected variables. You guys should really test this, VS is smart enough to generate the test stubs for you.&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_16.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="192" alt="image" src="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_thumb_7.png" width="504" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I just run the test and I get the result back as Passed:&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_18.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="120" alt="image" src="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_thumb.png" width="504" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Ok, moving back to the next way of getting our contact back, I have come up with this approach:&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_20.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="150" alt="image" src="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_thumb_8.png" width="504" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This actually will work but there's one tiny problem with it, if there's actually no element returned, this will throw a InvalidOperationException as the sequence doesn't contain any elements. I can easy surround this call with a try-catch block but that wouldn't feel right.&lt;/p&gt;  &lt;p&gt;Now comes FirstOrDefault to the rescue:&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_22.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="145" alt="image" src="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_thumb_9.png" width="504" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;FirstOrDefault will return the contact I'm looking for or it will return null if it doesn't find any contact that matches. If I actually passed in a contactId that doesn't exist and I change my unit test to do something like:&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_24.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="197" alt="image" src="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/FirstOrDefaulttotherescue_FC87/image_thumb_10.png" width="504" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This actually returned a Passed result. I'm sure there are other ways to implement this but I thought this might be worth sharing. &lt;/p&gt;  &lt;p&gt;Remeber, always check for null!&lt;/p&gt;</description><pubDate>Sun, 27 Jan 2008 00:49:54 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/jonelrienton/firstordefault-to-the-rescue</guid><category>.Net</category><category>LINQ</category><category>Visual Studio.Net</category></item><item><title>Microsoft Event</title><link>https://weblogs.asp.net:443/jonelrienton/microsoft-events</link><description>&lt;p&gt;Today I have been to a Microsoft event. The presenter talked about ASP.Net security, Visual Studio.Net 2008 and a few tips on how to secure your web applications. One thing I like about this kind of events is there's always hidden gold that you can walk with. One that stands out is when the presenter talked about ViewStateUserKey.&amp;#160; To avoid malicious user from using your ViewState value for XSS kind of attacks, setting the ViewStateUserKey in the Page_Init event of the Page will alleviate this.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/MicrosoftEvents_13644/ViewStateUserKey_2.png" mce_href="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/MicrosoftEvents_13644/ViewStateUserKey_2.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="88" alt="ViewStateUserKey" src="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/MicrosoftEvents_13644/ViewStateUserKey_thumb.png" width="504" border="0" mce_src="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/MicrosoftEvents_13644/ViewStateUserKey_thumb.png" /&gt;&lt;/a&gt;&amp;#160; &lt;/p&gt;  &lt;p&gt;The presenter also talked about &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=EFB9C819-53FF-4F82-BFAF-E11625130C25&amp;amp;displaylang=en" target="_blank" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyId=EFB9C819-53FF-4F82-BFAF-E11625130C25&amp;amp;displaylang=en"&gt;Microsoft Anti-Cross Site Scripting Library V1.5&lt;/a&gt;. This library will help you HtmlEncode text that your web application process.&lt;/p&gt;</description><pubDate>Fri, 25 Jan 2008 04:21:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/jonelrienton/microsoft-events</guid><category>ASP.NET</category><category>not null</category></item><item><title>Hello and welcome!</title><link>https://weblogs.asp.net:443/jonelrienton/hello-and-welcome</link><description>&lt;p&gt;It's finally nice to have a blog that actually belongs to a community of my own peers. I have been blogging using Google's Blogger for some time and I haven't really updated that site that much. I have been really busy between work and my family. Microsoft has been really generous to allow community members have their own blog space and even provide the Live Writer tool to conveniently post blog entries.&amp;#160; This is really sweet. You can get more information about setting up the Live Writer &lt;a title="Live Writer" href="http://joeon.net/post/2008/01/Setting-up-Live-Writer-to-Blog-on-Weblogsaspnet.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;I'm currently evaluating the free edition of the Community Server to see if we can leverage it for a project at work. Making it work in a Vista Business Edition is a bit challenging; none of my CSS and my images load. I have read quite a few post on what to do to make them load but so far to no avail. I have tried enabling the Static Content and that didn't seem to work. &lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/Helloandwelcome_142E3/Windows%2520Features_2.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="214" alt="Windows Features" src="https://aspblogs.blob.core.windows.net/media/jonelrienton/WindowsLiveWriter/Helloandwelcome_142E3/Windows%2520Features_thumb.png" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I have also tried setting up the folder permissions and added Network Service to the list and that didn't go anywhere either. I have created a copy of the Web folder and placed it under my wwwroot folder and it still didn't work. I will just probably move on and install this on my Windows 2003 VM to continue evaluating this product. &lt;/p&gt;  &lt;p&gt;I would like to personally thank Joe Stagner for setting up my account in weblogs.asp.net.&amp;#160; Till next time, remember, always check for null!&lt;/p&gt;</description><pubDate>Thu, 24 Jan 2008 04:57:41 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/jonelrienton/hello-and-welcome</guid><category>null</category></item></channel></rss>