<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Mehfuz's WebLog : Linq.Flickr</title><link>http://weblogs.asp.net/mehfuzh/archive/tags/Linq.Flickr/default.aspx</link><description>Tags: Linq.Flickr</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Asp.net MVC more Form post scenarios and Ajax</title><link>http://weblogs.asp.net/mehfuzh/archive/2008/09/29/asp-net-mvc-more-form-post-scenarios-and-ajax.aspx</link><pubDate>Sun, 28 Sep 2008 19:54:01 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6645726</guid><dc:creator>mehfuzh</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6645726</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6645726</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/09/29/asp-net-mvc-more-form-post-scenarios-and-ajax.aspx#comments</comments><description>&lt;p&gt;In the flickr explorer app made with Asp.net MVC and &lt;a target="_blank" href="http://www.codeplex.com/LINQFlickr"&gt;Athena&lt;/a&gt;, I was trying out some form post scenarios. In this post, I will add few things regarding MVC &lt;em&gt;form &lt;/em&gt;post and A&lt;em&gt;jax&lt;/em&gt; that is common to FlickrXplorer but can be used in general.&lt;/p&gt;  &lt;p&gt;Now, Asp.net MVC has some new Ajax features, one of this is the Ajax &lt;em&gt;form&lt;/em&gt; post. With this, you can easily make your web app actions Ajax enabled. The syntax is pretty simple.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="kwrd"&gt;using&lt;/span&gt; (Ajax.Form(&lt;span class="str"&gt;&amp;quot;AddComment&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;Comment&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;new&lt;/span&gt; AjaxOptions { UpdateTargetId = &lt;span class="str"&gt;&amp;quot;cmContainer&amp;quot;&lt;/span&gt;, 
           OnBegin = &lt;span class="str"&gt;@&amp;quot;function(sender, args) {
                $get('caWait').style.display = 'block';
           }&amp;quot;&lt;/span&gt;, 
           OnSuccess = &lt;span class="str"&gt;@&amp;quot;function(sender, args) {
             $get('caWait').style.display = 'none';
           }&amp;quot;&lt;/span&gt;, 
          }))
                            
       { &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;

...
...

&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; } &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span class="asp"&gt;The piece of snippet is taken from FlickrXplorer : CommentsControl.ascx where I used MVC Ajax to do comment posts. Here you can see that I can pass in the UpdateTargetId , where the output of ContentResult or&amp;#160; if it is ViewResult, it will contain the rendered html for it. Additionally, there is &lt;em&gt;OnBegin&lt;/em&gt; and &lt;em&gt;OnSuccess&lt;/em&gt; events where I can do things like show or hide the wait panel and any other things I might like to do.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="asp"&gt;On the client code , probably in your default.master you need to have the following references to make things work.&lt;/span&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;text/javascript&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;lt;%= Page.ResolveClientUrl(&amp;quot;&lt;/span&gt;~/&lt;span class="attr"&gt;Content&lt;/span&gt;/&lt;span class="attr"&gt;MicrosoftAjax&lt;/span&gt;.&lt;span class="attr"&gt;js&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;quot;) %&amp;gt;&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&amp;lt;script type=&lt;span class="str"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt; src=&lt;span class="str"&gt;&amp;quot;&amp;lt;%= Page.ResolveClientUrl(&amp;quot;&lt;/span&gt;~/Content/MicrosoftMvcAjax.js&lt;span class="str"&gt;&amp;quot;) %&amp;gt;&amp;quot;&lt;/span&gt; &amp;gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;span class="asp"&gt;Now, this is one way of doing things out. This basically injects the Ajax script in &lt;em&gt;onsubmit&lt;/em&gt; of the html &lt;em&gt;form&lt;/em&gt; where the actual magic happens. Now, this is not the only way, you might need to do custom tasks before the submission takes place, like check if the user has written something before pressing the submit button or selected his country &lt;em&gt;dropdown&lt;/em&gt; before pressing checkout in an air-ticket inventory system. For this kind of issue,&amp;#160; here is another cool way that it can be done.&lt;/span&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;function&lt;/span&gt; doAjaxSubmit(form, e, waitPanelId, targetToUpdate, methodName) {
    
    &lt;span class="kwrd"&gt;var&lt;/span&gt; isValid = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
    
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;typeof&lt;/span&gt; methodName != &lt;span class="str"&gt;'undefined'&lt;/span&gt;)
    {
        &lt;span class="kwrd"&gt;var&lt;/span&gt; validate = Function.createDelegate(&lt;span class="kwrd"&gt;this&lt;/span&gt;, methodName)    
        isValid = validate(form, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
    }

    &lt;span class="kwrd"&gt;if&lt;/span&gt; (isValid) {

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (e == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;
        
        Sys.Mvc.AsyncForm.handleSubmit(form, &lt;span class="kwrd"&gt;new&lt;/span&gt; Sys.UI.DomEvent(e),
        {
            insertionMode: Sys.Mvc.InsertionMode.replace,
            updateTargetId: targetToUpdate,
            onBegin: Function.createDelegate(form, &lt;span class="kwrd"&gt;function&lt;/span&gt;(sender, args) {
                $get(waitPanelId).style.display = &lt;span class="str"&gt;'block'&lt;/span&gt;;
            }),
            onSuccess:
            Function.createDelegate(form, &lt;span class="kwrd"&gt;function&lt;/span&gt;(sender, args) {
                $get(waitPanelId).style.display = &lt;span class="str"&gt;'none'&lt;/span&gt;;
            })
        });

    }
    &lt;span class="kwrd"&gt;else&lt;/span&gt; {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;
    }
}&lt;/pre&gt;

&lt;p&gt;So, I have written a tiny JS routine that is a similar script that Ajax.Form injects in &lt;em&gt;onsubmit&lt;/em&gt; event of html &lt;em&gt;form&lt;/em&gt; but with few changes. As, we can see that I need to pass the &lt;em&gt;form&lt;/em&gt; instance (this), event (in this case submit), the target where the update will be pushed in and a delegate method if provided it will process the submit only if it passes the validation written by the implementer.&lt;/p&gt;

&lt;p&gt;In the FlickrXplorer : CommentsControl.ascx i have modified previous the html block like&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; 
IDictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt; formParams = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt;();
formParams.Add(&lt;span class="str"&gt;&amp;quot;onsubmit&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;@&amp;quot;return doAjaxSubmit(this, event, 'caWait', 'cmContainer', function(sender, args) 
{
    return validateRequiredText('errComment', 'txtComment');
});&amp;quot;&lt;/span&gt;);

&lt;span class="kwrd"&gt;using&lt;/span&gt; (Html.Form(&lt;span class="str"&gt;&amp;quot;Comment&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;AddComment&amp;quot;&lt;/span&gt;, Microsoft.Web.Mvc.FormMethod.Post, formParams))
                    
{ &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;

&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= Html.Hidden(&lt;span class="str"&gt;&amp;quot;photoId&amp;quot;&lt;/span&gt;, photoId) &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;
...
...

&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; 
} &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;In this case, I have converted the Ajax.Form to Html.Form, where I have hooked the &lt;em&gt;onsubmit &lt;/em&gt;with &lt;em&gt;doAjaxSubmit&lt;/em&gt; routine with few parameters. Inside the call back method, I have written the required logic for validating required field. So, if people lefts the comment textarea intentionally blank and tries to do a post he might see.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Asp.netMVCmoreFormpostscenariosandAjax_12874/image_4.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Asp.netMVCmoreFormpostscenariosandAjax_12874/image_thumb_1.png" width="440" height="94" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Now, moving on to the next section, I would like to like see my pager do MVC form post but I would like to see a continue of parents parameters. Let's take the use case.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Asp.netMVCmoreFormpostscenariosandAjax_12874/image_6.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Asp.netMVCmoreFormpostscenariosandAjax_12874/image_thumb_2.png" width="503" height="215" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;In other words, I need to delegate &lt;em&gt;form&lt;/em&gt; action from parent to child. There are plenty of ways to do it. In my way, I have created a HtmlHelper extension method that prepares my child form with query params that come from the parent request.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; RenderRequiredFormPostElements(&lt;span class="kwrd"&gt;this&lt;/span&gt; HtmlHelper htmlHelper, &lt;span class="kwrd"&gt;string&lt;/span&gt; paramToExclude)
{
    &lt;span class="kwrd"&gt;string&lt;/span&gt; url = HttpContext.Current.Request.Path;

    StringBuilder builder = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder();
    NameValueCollection queries = HttpContext.Current.Request.QueryString;

    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt; name &lt;span class="kwrd"&gt;in&lt;/span&gt; queries.AllKeys)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt;.Compare(name, paramToExclude, &lt;span class="kwrd"&gt;true&lt;/span&gt;) == 0)
        {
            &lt;span class="rem"&gt;//skip&lt;/span&gt;
        }
        &lt;span class="kwrd"&gt;else&lt;/span&gt;
        {
            builder.Append(htmlHelper.Hidden(name, &lt;span class="kwrd"&gt;new&lt;/span&gt; {&lt;span class="kwrd"&gt;value&lt;/span&gt; = queries[name]}));
        }
    }
    &lt;span class="kwrd"&gt;return&lt;/span&gt; builder.ToString();
}&lt;/pre&gt;

&lt;p&gt;Here it renders html hidden elements based the current url, also I can pass in a particular query param (in this case &amp;quot;page&amp;quot;) which I don't want to be processed. Finally, in the FlickrXplorer : Pager.ascx i have added the following lines&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;pagerForm&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;method&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;GET&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;action&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;lt;%= HttpContext.Current.Request.Path %&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= Html.Hidden(&lt;span class="str"&gt;&amp;quot;page&amp;quot;&lt;/span&gt;) &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;         
&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; = Html.RenderRequiredFormPostElements(&lt;span class="str"&gt;&amp;quot;page&amp;quot;&lt;/span&gt;) &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;             

...
...&lt;/pre&gt;

&lt;p&gt;Here, to include that&amp;#160; pager action is bound to the current url , which is in turn bound to an action in the controller class. Therefore, in this case &lt;em&gt;Request.Path&lt;/em&gt; points to an action url /Photo/{action}&amp;#160; with paging value. Also, the possible action methods for which paging&amp;#160; value will be supplied need to handle the case if there is no paging.&lt;/p&gt;

&lt;p&gt;That's all for now. All the example are shown here, ties to Asp.net MVC 5. You can find codes running at &lt;a href="http://www.codeplex.com/flickrXplorer"&gt;www.codeplex.com/flickrXplorer&lt;/a&gt; , please go to the source tab to grab the nightly build.&lt;/p&gt;

&lt;p&gt;Enjoy !!!&lt;/p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f09%2f29%2fasp-net-mvc-more-form-post-scenarios-and-ajax.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f09%2f29%2fasp-net-mvc-more-form-post-scenarios-and-ajax.aspx" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6645726" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Linq.Flickr/default.aspx">Linq.Flickr</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/asp.net/default.aspx">asp.net</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Ajax/default.aspx">Ajax</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/AspNetMvc/default.aspx">AspNetMvc</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/FlickrXplorer/default.aspx">FlickrXplorer</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Athena/default.aspx">Athena</category></item><item><title>Athena - A LINQ to flickr API (Release 1.4)</title><link>http://weblogs.asp.net/mehfuzh/archive/2008/08/02/athena-a-linq-to-flickr-api-release-1-4.aspx</link><pubDate>Sat, 02 Aug 2008 09:07:51 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6470395</guid><dc:creator>mehfuzh</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6470395</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6470395</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/08/02/athena-a-linq-to-flickr-api-release-1-4.aspx#comments</comments><description>&lt;p&gt;Last week, I released a new version of LINQ.flickr, which I named as &lt;a href="http://www.codeplex.com/LINQFlickr" target="_blank"&gt;Athena&lt;/a&gt; from release 1.4. It covers few features from flickr service, also now I have updated it with the latest &lt;a href="http://www.codeplex.com/LinqExtender" target="_blank"&gt;LINQExtender&lt;/a&gt; (pre release version)&amp;#160; containing updated Object Tracking Service (OTS) that will enable it to update photos and comments as if like LINQ to SQL.&lt;/p&gt;  &lt;p&gt;First of the interesting features that most others asked me to implement is the Extras support, with this you can get additional information about your photos by querying with Extras &lt;em&gt;enum&lt;/em&gt;.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;var query = (from photo &lt;span class="kwrd"&gt;in&lt;/span&gt; context.Photos
            &lt;span class="kwrd"&gt;where&lt;/span&gt; photo.SearchText == &lt;span class="str"&gt;&amp;quot;Redmond&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp; p.Extras == (ExtrasOption.Views 
| ExtrasOption.Date_Taken | ExtrasOption.Date_Upload)
            select photo).Skip(0).Take(10);&lt;/pre&gt;

&lt;p&gt;This will return 10 photos contains word &amp;quot;Redmond&amp;quot;, additionally it will have &lt;em&gt;Photos.Views&lt;/em&gt; , &lt;em&gt;Photos.TakeOn&lt;/em&gt; and Photo.UploadedOn that user might find useful. The extras options is provided by flickr and it has options like GEO, tags , etc.&lt;/p&gt;

&lt;p&gt;Athena , now covers two new endpoints.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;flickr.photos.setMeta&lt;/em&gt; and &lt;em&gt;flickr.photos.comments.editcomment&lt;/em&gt;.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Comment comment = (from c &lt;span class="kwrd"&gt;in&lt;/span&gt; context.Photos.Comments
&lt;span class="kwrd"&gt;where&lt;/span&gt; c.Id == &lt;span class="str"&gt;&amp;quot;1234&amp;quot;&lt;/span&gt;
select c).Single();
 
comment.Text = &lt;span class="str"&gt;&amp;quot;This is a updated comment.&amp;quot;&lt;/span&gt;;
coment.SubmitChanges();
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;&lt;/pre&gt;

&lt;p&gt;This will update the comment for me. Notice that it tracks the object for update and automatically fires the appropriate method to do the update. It comes as&amp;#160; a part of enhanced LinqExtender&amp;#160; OTS which I will describe a bit more in other post about how to implement it. &lt;/p&gt;

&lt;p&gt;Finally, the easy authentication method that I already described in my previous post, take a look at that as well. Also, the coming update will have photo set support and watch out for that as well. There are few new development updates like one click test and deployment package creation with NAnt that lets me update my app with the latest source without running IDE and test program. There are also a lot of re-factors and performance enhancements that makes the API more stable.&lt;/p&gt;

&lt;p&gt;That's it. Enjoy and file me bugs!!&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f08%2f02%2fathena-a-linq-to-flickr-api-release-1-4.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f08%2f02%2fathena-a-linq-to-flickr-api-release-1-4.aspx" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6470395" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LinqExtender/default.aspx">LinqExtender</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Linq.Flickr/default.aspx">Linq.Flickr</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Athena/default.aspx">Athena</category></item><item><title>Making authenticated calls to flickr</title><link>http://weblogs.asp.net/mehfuzh/archive/2008/07/29/making-authenticated-calls-to-flickr.aspx</link><pubDate>Mon, 28 Jul 2008 19:16:23 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6454666</guid><dc:creator>mehfuzh</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6454666</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6454666</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/07/29/making-authenticated-calls-to-flickr.aspx#comments</comments><description>&lt;p&gt;There are few things to know , when getting photos from your stream , adding comments and overall doing adding and deletion of your photos. As with flickr you can take a look at this url =&amp;gt; &lt;a title="http://www.flickr.com/services/api/auth.spec.html" href="http://www.flickr.com/services/api/auth.spec.html"&gt;http://www.flickr.com/services/api/auth.spec.html&lt;/a&gt;&amp;#160; for authentication spec to learn more. But with &lt;a href="http://www.codeplex.com/LINQFlickr" target="_blank"&gt;Athena (formerly known as LINQ.Flickr)&lt;/a&gt; it's pretty easy to get things going. Last week, I made an update to the &lt;a href="http://www.codeplex.com/FlickrXplorer" target="_blank"&gt;FlickrXplorer&lt;/a&gt; (The MVC starter project you don't want to miss :-)) project that now enables you to add comments for photos. There is a one click login that will take you to flickr, ask you once for the permission to grant the app for data access and finally will take you back to the place from where you were left off.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Makingauthenticatedcallstoflickr_CB2/image_8.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="393" alt="image" src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Makingauthenticatedcallstoflickr_CB2/image_thumb_3.png" width="408" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now, concept with MVC app is to call a controller url , and finally point flickr to a second controller url that will bring the user to last page, if everything works fine. This whole thing is done by Athena on behalf without a single line of code on client app. &lt;/p&gt;  &lt;p&gt;To start off , lets create a context class.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;FlickrContext context = &lt;span class="kwrd"&gt;new&lt;/span&gt; FlickrContext();&lt;/pre&gt;

&lt;p&gt;Authentication done in two ways, first one is the auto authentication.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;var query = from photo &lt;span class="kwrd"&gt;in&lt;/span&gt; context.Photos
                    &lt;span class="kwrd"&gt;where&lt;/span&gt; photo.SearchText == &lt;span class="str"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp; photo.ViewMode == ViewMode.Owner
                    select photo;&lt;/pre&gt;

&lt;p&gt;&lt;style type="text/css"&gt;





.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/p&gt;

&lt;p&gt;This query tries to search in my photo stream with word &amp;quot;Home&amp;quot;,&amp;#160; where the owner is the caller himself. This will automatically take me to the flickr authentication page. However, this is good for desktop based application, where it will fire up the browser , let me authenticate and on closing, it will continue from next line of code. This will also work for web apps, but in case if we need to do something else on successful return, we need a manual way for sure.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;context.Authenticate();&lt;/pre&gt;

&lt;p&gt;Lets say, I call /Photo/Security/Auth url which runs the above line in the controller class that will eventually fire the authentication&amp;#160; process. Here to note that once the authentication process is complete all the successive calls will return Authentication token class, which we can use for showing user status or like &amp;quot;Welcome XYZ...&amp;quot;. &lt;/p&gt;

&lt;pre class="csharpcode"&gt;AuthToken token = context.Authenticate();

&lt;span class="kwrd"&gt;if&lt;/span&gt; (token != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
{
   People people = (from p &lt;span class="kwrd"&gt;in&lt;/span&gt; context.Peoples
                               &lt;span class="kwrd"&gt;where&lt;/span&gt; p.NsId == token.UserId
                               select p).Single();
&lt;span class="rem"&gt;// do the rest.&lt;/span&gt;
}&lt;/pre&gt;

&lt;p&gt;Finally, if we are on a public computer, we surely don't want to leave without logging off. So, there should be a manual call for that as well.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;context.ClearToken();&lt;/pre&gt;

&lt;p&gt;And, it says all. Technically, Athena stores a token in the App Directory for desktop application with the given path in config for &lt;em&gt;FlickrSettings&lt;/em&gt;. In web application, it stores the token in user's browser cookie with 30 days of lifeline for current site which of course goes out as soon as you logout. Token is used by flickr for validating authenticated calls and also by the API to make useful decisions in minimizing service calls.&lt;/p&gt;

&lt;p&gt;Hope that gives some light on those who likes to give authenticated features to their personal photo app without much of hair loss. &lt;/p&gt;

&lt;p&gt;Again, check things out : &lt;a href="http://www.codeplex.com/linqflickr" target="_blank"&gt;www.codeplex.com/linqflickr&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f07%2f29%2fmaking-authenticated-calls-to-flickr.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f07%2f29%2fmaking-authenticated-calls-to-flickr.aspx" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6454666" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Linq.Flickr/default.aspx">Linq.Flickr</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Athena/default.aspx">Athena</category></item><item><title>Implement Master-Detail layout with ASP.NET MVC</title><link>http://weblogs.asp.net/mehfuzh/archive/2008/06/30/implement-master-detail-layout-with-asp-net-mvc.aspx</link><pubDate>Sun, 29 Jun 2008 19:48:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6336439</guid><dc:creator>mehfuzh</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6336439</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6336439</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/06/30/implement-master-detail-layout-with-asp-net-mvc.aspx#comments</comments><description>&lt;P&gt;This is the first of posts that I am making to show out the things you can do with ASP.NET MVC. Also, it shows what I have done while building &lt;A href="http://www.codeplex.com/FlickrXplorer" target=_blank mce_href="http://www.codeplex.com/FlickrXplorer"&gt;FlickrXplorer&lt;/A&gt;. I am bit lazy to write one article for it, so I thought rather to start it here.&lt;/P&gt;
&lt;P&gt;In this post, I will show how you can implement a master-detail layout that invokes MVC controller to process its data and uses Ajax to do it in a non postback manner.&lt;/P&gt;
&lt;P&gt;If you have looked though &lt;A href="http://www.codeplex.com/FlickrXplorer" target=_blank mce_href="http://www.codeplex.com/FlickrXplorer"&gt;FlickrXplorer&lt;/A&gt;, you must have noticed that every list of images is tied with a detail view in a way that if user performs any action on the list ("click") , the detail view is updated accordingly. &lt;/P&gt;
&lt;P&gt;Let's see the action flow below&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/ImplementMasterDetaillayou.netMVCandajax_120C0/image_10.png" mce_href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/ImplementMasterDetaillayou.netMVCandajax_120C0/image_10.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=329 alt=image src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/ImplementMasterDetaillayou.netMVCandajax_120C0/image_thumb_4.png" width=463 border=0 mce_src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/ImplementMasterDetaillayou.netMVCandajax_120C0/image_thumb_4.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;It is almost clear that when you select an image it calls a Controller method or an Action method to be more precise. In this case, let's say that it is /Photo/Detail/112233. To map this a simple line in global.asax follows&lt;/P&gt;&lt;PRE class=csharpcode&gt;routes.MapRoute(&lt;SPAN class=str&gt;"Detail"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"Photo/Detail/{photoId}"&lt;/SPAN&gt;,
 &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; { controller = &lt;SPAN class=str&gt;"Photo"&lt;/SPAN&gt;, action = &lt;SPAN class=str&gt;"Detail"&lt;/SPAN&gt; });&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;STYLE type=text/css&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;This will result in the call of &lt;EM&gt;PhotoController.Detail&lt;/EM&gt;, when user hits the above url. Inside detail view its pretty simple.&lt;/P&gt;&lt;PRE class=csharpcode&gt;[FilterResponse]
&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; ActionResult Detail(&lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; photoId)
{
    &lt;SPAN class=kwrd&gt;try&lt;/SPAN&gt;
    {
        PhotoDetail detail = model.GetPhoto(photoId); 
        &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; View(detail);
    }
    &lt;SPAN class=kwrd&gt;catch&lt;/SPAN&gt; (Exception ex)
    {
        &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; View(&lt;SPAN class=str&gt;"Error"&lt;/SPAN&gt;, 
&lt;SPAN class=kwrd&gt;                    new&lt;/SPAN&gt; ControllerException
      { ErrorUrl = HttpContext.Request.RawUrl, Message = ex.Message });
    }
}&lt;/PRE&gt;
&lt;P&gt;As, expected it calls the model to get the photo and returns the &lt;EM&gt;ViewResult&lt;/EM&gt;. Here, I haven't done any content related processing rather made a ViewPage named Detail.aspx which the MVC framework calls. By default, MVC framework looks for the ViewPage or ViewControl with name equals to the Action name, but &lt;EM&gt;View&lt;/EM&gt; has other overrides that let me call other ViewPage/ViewControl as well. This is what done above when any error occurs, which calls Shared/Error.aspx. It is to be noted that if you have multiple controller and you want to access the same view from different controller, then you need to place it in the &lt;EM&gt;Shared&lt;/EM&gt; folder, which will make it accessible by all controllers. &lt;/P&gt;
&lt;P&gt;In the snippet, we also see that there is a FilterResponse attribute that will cache the response for same parameter set once the first call is made. FlickrResponse is inherited from MVC.ActionFilterAttribute attribute that provides a way to do some custom actions like caching and compression of http content.&lt;/P&gt;
&lt;P&gt;So far, I have mapped the url and added the action method. Now, its time to get the result and show them in UI but I don't want any postbacks or redirects for it. So, I have used a callback model that did the work for me.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;function&lt;/SPAN&gt; renderContent(elementId, loadElementId, url, callback) {
    &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; element = $get(elementId);
    $get(loadElementId).style.display = &lt;SPAN class=str&gt;"block"&lt;/SPAN&gt;;

    &lt;SPAN class=rem&gt;// Create the WebRequest object.&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; wRequest = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; Sys.Net.WebRequest();

    &lt;SPAN class=rem&gt;// Set the request Url.  &lt;/SPAN&gt;
    wRequest.set_url(url);
    &lt;SPAN class=rem&gt;// Set the request verb.&lt;/SPAN&gt;
    wRequest.set_httpVerb(&lt;SPAN class=str&gt;"GET"&lt;/SPAN&gt;);
    &lt;SPAN class=rem&gt;// Set the Completed event handler, &lt;/SPAN&gt;
    &lt;SPAN class=rem&gt;// for processing return data&lt;/SPAN&gt;
    wRequest.add_completed(&lt;SPAN class=kwrd&gt;function&lt;/SPAN&gt;(sender, eventArgs) 
    {
        &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (sender.get_responseAvailable()) 
        {
            element.innerHTML = sender.get_responseData();
            $get(loadElementId).style.display = &lt;SPAN class=str&gt;"none"&lt;/SPAN&gt;;
            
            &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (&lt;SPAN class=kwrd&gt;typeof&lt;/SPAN&gt; callback != &lt;SPAN class=str&gt;'undefined'&lt;/SPAN&gt;)
                callback();
            
        }
    });
    &lt;SPAN class=rem&gt;// Make the request.&lt;/SPAN&gt;
    wRequest.invoke();
}&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;
&lt;STYLE type=text/css&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;
&lt;/P&gt;
&lt;P&gt;Here, we see that &lt;EM&gt;renderContent&lt;/EM&gt; takes in the Id of the element that will contain the rendered content and loading element that will be visible while the content is being processed. Optionally, we can pass in a parameter-less void callback which can be invoked after the content is processed. In that case, we might like to start the loading of comments after we have rendered the detail page. This &lt;EM&gt;renderContent&lt;/EM&gt; is invoked while a user selects a photo from the list, this is a bit generic method which can be used for any callback scenarios. Therefore, for rendering photo detail, I wrapped it around so that it takes only a photoId. &lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;function&lt;/SPAN&gt; renderDeail(photoId, ignoreHash) {
    &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (ignoreHash == 0) {
        &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (window.location.hash == &lt;SPAN class=str&gt;''&lt;/SPAN&gt;) {
            &lt;SPAN class=rem&gt;// take the default one &lt;/SPAN&gt;
            window.location.hash = photoId;
        }
        &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt; {
            photoId = getPhotoIdFromHash();
        }
    }
    &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt; {
        window.location.hash = photoId;
    }
    &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; url = &lt;SPAN class=str&gt;'&amp;lt;%= Html.ActionUrl("Photo", "Detail", new { photoId = "{0}" }) %&amp;gt;'&lt;/SPAN&gt;;
    url = String.format(unescape(url), photoId);
    renderContent(&lt;SPAN class=str&gt;"detailView"&lt;/SPAN&gt;, &lt;SPAN class=str&gt;"loadingView"&lt;/SPAN&gt;, url, loadComments);
}&lt;/PRE&gt;
&lt;P&gt;
&lt;STYLE type=text/css&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;
&lt;EM&gt;renderDetail&lt;/EM&gt;&amp;nbsp; takes a photoId and ignoreHash := true/false. Inside, it uses Html.ActionUrl to process the url and then formats it with photoId and finally calls the &lt;EM&gt;renderContent&lt;/EM&gt;. Html.ActionUrl is an extension method which is coded by me, the original is Html.ActionLink. So please dont get confused :-). I could have passed the url by hand but using ActionUrl&amp;nbsp; it creates the url on basis of the route mapping in global.asax. Also, for Photo controller if I change the url from /photo/detail/id to /p/detail/id, then I don't have to go everywhere in order to change the references.&lt;/P&gt;
&lt;P&gt;Finally, while loading photo from url, I use &lt;EM&gt;window.hash&lt;/EM&gt; to navigate to the selected photo, which is updated when a photo is clicked to show and thus, I have the master-detail layout yet url copy-paste facility.&lt;/P&gt;
&lt;P&gt;That's it for now, I leave it on to the reader to explore it more in &lt;A href="http://www.codeplex.com/flickrXplorer" target=_blank mce_href="http://www.codeplex.com/flickrXplorer"&gt;Codeplex&lt;/A&gt;. Also, hope that the introduction helps. Please note that some of the features like 2nd step loading of comments will be supported from 1.2 release (please check it out), so the JS might slightly differ to what is shown here.&lt;/P&gt;
&lt;P&gt;Check it live at &lt;A href="http://www.flickrmvc.net/" target=_blank mce_href="http://www.flickrmvc.net"&gt;flickrmvc.net&lt;/A&gt; - send me feedbacks and updates.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f06%2f30%2fimplement-master-detail-layout-with-asp-net-mvc.aspx" mce_href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f06%2f30%2fimplement-master-detail-layout-with-asp-net-mvc.aspx"&gt;&lt;IMG alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f06%2f30%2fimplement-master-detail-layout-with-asp-net-mvc.aspx" border=0 mce_src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f06%2f30%2fimplement-master-detail-layout-with-asp-net-mvc.aspx"&gt;&lt;/A&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6336439" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Linq.Flickr/default.aspx">Linq.Flickr</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/asp.net/default.aspx">asp.net</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Ajax/default.aspx">Ajax</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/AspNetMvc/default.aspx">AspNetMvc</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/FlickrXplorer/default.aspx">FlickrXplorer</category></item><item><title>Replace SortedDictionary with LINQ query - Part 2 (with comparison)</title><link>http://weblogs.asp.net/mehfuzh/archive/2008/06/18/replace-sorteddictionary-with-linq-query-part-2-with-comparison.aspx</link><pubDate>Tue, 17 Jun 2008 20:09:16 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6287527</guid><dc:creator>mehfuzh</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6287527</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6287527</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/06/18/replace-sorteddictionary-with-linq-query-part-2-with-comparison.aspx#comments</comments><description>&lt;p&gt;In my previous &lt;a href="http://weblogs.asp.net/mehfuzh/archive/2008/06/17/replace-sorteddictionary-with-linq-query.aspx" target="_blank"&gt;post&lt;/a&gt;, I have said that using LINQ query instead of &lt;em&gt;SortedDictionary&lt;/em&gt; not only could be useful , elegant but also less processor intensive. In this post, I will show you a real comparison between the same the method but one with &lt;em&gt;SortedDictionary&lt;/em&gt; and other with LINQ &lt;em&gt;orderby&lt;/em&gt; query. I wrote a simple console application that mimics the action of &lt;em&gt;GetSignature&lt;/em&gt; in LINQ.Flickr. Here, I will focus only on the &lt;em&gt;sorting&lt;/em&gt; part that's why I removed the hashing and initialization of the method. &lt;/p&gt;  &lt;p&gt;So, lets assume there are 10 url pairs that we need to sort for getting the signature. So, we need to create an array of 8 items and the processing method inserts another 2 (api_key and method name). Finally, when I run the two routines and took a snapshot from &lt;strong&gt;jetbrain's&lt;/strong&gt; &lt;strong&gt;dottrace , &lt;/strong&gt;I saw the following&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/ReplaceSortedDictionarywithLINQqueryPart_8A8/comparisonInit_1.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="127" alt="comparisonInit" src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/ReplaceSortedDictionarywithLINQqueryPart_8A8/comparisonInit_thumb_1.jpg" width="508" border="0" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Now, you can see that there are two methods &lt;em&gt;TestSortedItemsWithSortedDic(SortedDictionary)&lt;/em&gt; and &lt;em&gt;TestSortedItems&lt;/em&gt; (LINQ). The difference is almost 3 times the LINQ &lt;em&gt;orderby&lt;/em&gt; query. Expanding the &lt;em&gt;TestSortedItemsWithSortedDic &lt;/em&gt;will reveal the following&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/ReplaceSortedDictionarywithLINQqueryPart_8A8/sorted_2.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="263" alt="sorted" src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/ReplaceSortedDictionarywithLINQqueryPart_8A8/sorted_thumb_2.jpg" width="527" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;As you can see that adding items into sorted dictionary takes around 6.37% of the CPU cycle which is definitely because of the sort algorithm that it runs on each add. Also, there is another 1.39% during the initialization. Only these two items take up 7.76%, let alone the other &lt;em&gt;SortedDictionary&lt;/em&gt; entries. Now, lets see how the processing with LINQ &lt;em&gt;orderby&lt;/em&gt; looks like&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/ReplaceSortedDictionarywithLINQqueryPart_8A8/LINQ_1.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="165" alt="LINQ" src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/ReplaceSortedDictionarywithLINQqueryPart_8A8/LINQ_thumb_1.jpg" width="536" border="0" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;LINQ iteration takes up 1.77%(where the original execution take place) , &lt;em&gt;Dictionary.Add&lt;/em&gt; takes 0.54% comparing to 6.37% with sorted dictionary and additional &lt;em&gt;orderby&lt;/em&gt; and &lt;em&gt;select &lt;/em&gt;take 0.17 and 0.14% respectively. So, in total &lt;em&gt;add&lt;/em&gt; and sorting &lt;em&gt;takes&lt;/em&gt; up to (1.77 + 0.54 + 0.17 + 0.14) 3.39% of CPU cycles. Here to include that, highest CPU index may vary with current load, but the ratio remains almost the same.&lt;/p&gt;  &lt;p&gt;Therefore, it is almost clear that we can replace &lt;em&gt;SortedDictionary&lt;/em&gt; with LINQ and without it .stripped down version of .net in Silverlight is not a bad idea :-). Also, those who commented on my last post for live comparison thank you !!. You can also download the test code I have used &lt;a href="http://weblogs.asp.net/mehfuzh/ProcessTest.zip" target="_blank"&gt;here&lt;/a&gt; and run it in dottrace to see it live (I have used dottrace 3.1). &lt;/p&gt;  &lt;p&gt;Have fun!!&lt;/p&gt; &lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f06%2f18%2freplace-sorteddictionary-with-linq-query-part-2-with-comparison.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f06%2f18%2freplace-sorteddictionary-with-linq-query-part-2-with-comparison.aspx" border="0" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6287527" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Linq.Flickr/default.aspx">Linq.Flickr</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/dottrace/default.aspx">dottrace</category></item><item><title>Replace SortedDictionary with LINQ query</title><link>http://weblogs.asp.net/mehfuzh/archive/2008/06/17/replace-sorteddictionary-with-linq-query.aspx</link><pubDate>Mon, 16 Jun 2008 18:43:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6283174</guid><dc:creator>mehfuzh</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6283174</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6283174</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/06/17/replace-sorteddictionary-with-linq-query.aspx#comments</comments><description>&lt;p&gt;With &lt;a href="http://www.codeplex.com/LINQFlickr" target="_blank"&gt;LINQ.Flickr&lt;/a&gt; it is quite necessary to get signature on parameters in order to do authenticated flickr photo get. As with the signature, it has to be sorted by parameter then to be hashed by MD5. Previously, I used to use SortedDictionary dictionary to do so, but thinking a little bit I learned that we actually don't need SortedDictionary anymore after we have LINQ. May be that's why the product team at Microsoft removed SortedDictionary from stripped down version of .net that comes with SilverLight. &lt;/p&gt;  &lt;p&gt;Now, off to code, lets say I want 10 photos from my photo stream in flickr, to achieve that&amp;#160; I would simply write&lt;/p&gt;  &lt;pre class="csharpcode"&gt;var query = (from photo &lt;span class="kwrd"&gt;in&lt;/span&gt; context.Photos
            &lt;span class="kwrd"&gt;where&lt;/span&gt; photo.ViewMode == ViewMode.Owner
            select photo).Take(10);&lt;/pre&gt;

&lt;p&gt;Behind the scene, it will first try to authenticate me, if I am not already then it will try to do it and finally it will make an authenticated call to get my photos from my flickr account. Using SortedDictionary, the sorting of signature items used to be done on the fly but the overhead is that on every new item inserted in the dictionary due to each parameter of REST call, it runs the sort logic. This is of course a waste of processor speed. So, I replaced all the lines that look like &lt;/p&gt;

&lt;pre class="csharpcode"&gt;IDictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; sortedSigItems 
= &lt;span class="kwrd"&gt;new&lt;/span&gt; SortedDictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;();&lt;/pre&gt;
&lt;style type="text/css"&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;with &lt;/p&gt;

&lt;pre class="csharpcode"&gt;IDictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; sigItems = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;();&lt;/pre&gt;

&lt;p&gt;Finally, inside my GetSignature method at BaseRepository of LINQ.Flickr I added the following lines, before final toString stuff.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;var query = from sigItem &lt;span class="kwrd"&gt;in&lt;/span&gt; sigItems
            orderby sigItem .Key ascending
            select sigItem.Key + sigItem .Value;

&lt;font color="#008000"&gt;// do the rest with sorted list.&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;The whole thing is much pleasing with LINQ query and less processor intensive.So next time when you think about sorting, think about LINQ first :-)&lt;/p&gt;

&lt;p&gt;Have fun!!!&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff0000"&gt;Continued with comparison in part 2 of this post.&lt;/font&gt;&lt;/p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f06%2f17%2freplace-sorteddictionary-with-linq-query.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f06%2f17%2freplace-sorteddictionary-with-linq-query.aspx" border="0" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6283174" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Linq.Flickr/default.aspx">Linq.Flickr</category></item><item><title>Flickr web app with MVC preview 3 [Cont..]</title><link>http://weblogs.asp.net/mehfuzh/archive/2008/05/31/flickr-web-app-with-mvc-preview-3-cont.aspx</link><pubDate>Sat, 31 May 2008 07:43:18 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6236287</guid><dc:creator>mehfuzh</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6236287</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6236287</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/05/31/flickr-web-app-with-mvc-preview-3-cont.aspx#comments</comments><description>&lt;p&gt;In my last post, I have mentioned of creating Flickr app with Asp.net MVC. In recent update I have modified it with Asp.net MVC Preview 3.&lt;/p&gt;  &lt;p&gt;You can find a general reference about the project &lt;a href="http://weblogs.asp.net/mehfuzh/archive/2008/05/27/flickr-viewer-an-asp-net-mvc-photo-app-for-flickr.aspx" target="_blank"&gt;here&lt;/a&gt;. But in this post, I will say, what are the changes due to the new release and where to start especially.&lt;/p&gt;  &lt;p&gt;In previous release of ASP.net MVC you had &lt;em&gt;RenderView&lt;/em&gt;, which lets you render your UI right from the controller and controller classes are with &lt;em&gt;void&lt;/em&gt; return type, now with new release this is slightly changed. In case of the FLickrViewer app, I have a PhotoController, where I did the following changes.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Tags(&lt;span class="kwrd"&gt;string&lt;/span&gt; name, &lt;span class="kwrd"&gt;int&lt;/span&gt;? page)
{
    ViewData[&lt;span class="str"&gt;&amp;quot;Title&amp;quot;&lt;/span&gt;] = name;

    PhotoData photoData = &lt;span class="kwrd"&gt;new&lt;/span&gt; PhotoData();
    
    &lt;span class="rem"&gt;// ........ more code here  ......&lt;/span&gt;

    &lt;span class="kwrd"&gt;return&lt;/span&gt; View(photoData);
}&lt;/pre&gt;
&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;As you can see, the data is passed as ActionResult by a &lt;em&gt;View&lt;/em&gt; routine, in this way it becomes more TDD friendly, where I don't need to mock HttpContext to compare results from Test class. From UI layer. Also, it lets you have different sets of results in ViewData. For example, i want to populate View's Title property from &lt;em&gt;ViewDataDictionary&lt;/em&gt; and get the tags from its &lt;em&gt;Model&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Therefore, I can do the following to have dynamic browser title&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; Photos for tag - &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= ViewData[&lt;span class="str"&gt;&amp;quot;Title&amp;quot;&lt;/span&gt;] &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And, then access the Model property to get PhotoData.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; 
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (ViewData.Model != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
    {
        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (FlickrViewer.Web.Objects.PopularTag tag &lt;span class="kwrd"&gt;in&lt;/span&gt; ViewData.Model)
        {
            &lt;span class="rem"&gt;// .. actual code&lt;/span&gt;
        }
    }&lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Pretty cool, in terms of separating result and UI data. :-).&amp;#160; Another good update is the routing helpers. We can now ignore particular URL extensions to be sent to controllers by &lt;em&gt;IgnoreRoutes&lt;/em&gt; and can use the new easy construct called MapRoute for mappping URLs to controllers.&lt;/p&gt;

&lt;p&gt;In global.asax, we can register and ignore routes like&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute(&lt;span class="str"&gt;&amp;quot;{resource}.axd/{*pathInfo}&amp;quot;&lt;/span&gt;);
    routes.MapRoute(&lt;span class="str"&gt;&amp;quot;Detail&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;Photo.mvc/Detail/{photoId}&amp;quot;&lt;/span&gt;, 
                     &lt;span class="kwrd"&gt;new&lt;/span&gt; { controller = &lt;span class="str"&gt;&amp;quot;Photo&amp;quot;&lt;/span&gt;, action = &lt;span class="str"&gt;&amp;quot;Detail&amp;quot;&lt;/span&gt; });
}&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;/p&gt;
&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;These are few of loads of new additions to MVC Preview 3. In coming posts, I will tell more about how to use Ajax with MVC to construct master-detail UI, but you can check it out easily by digging into the source.&lt;/p&gt;

&lt;p&gt;The source can be divided into four parts&lt;/p&gt;

&lt;ol&gt;
  &lt;ol&gt;
    &lt;li&gt;UI - that uses Asp.net Ajax and JS and Html to render things out. &lt;/li&gt;

    &lt;li&gt;PhotoController - prepares the data for rendering. &lt;/li&gt;

    &lt;li&gt;PhotoModel -&amp;gt; talks with Flickr using &lt;a href="http://www.codeplex.com/LINQFlickr" target="_blank"&gt;LINQ.Flickr&lt;/a&gt;. &lt;/li&gt;

    &lt;li&gt;A separate test project that uses NUNIT and Rhino mock to test controller. &lt;/li&gt;
  &lt;/ol&gt;
&lt;/ol&gt;

&lt;p&gt;All together it makes out a MVC project :-). Again, get the copy of the source from &lt;a href="http://www.codeplex.com/flickrviewer"&gt;www.codeplex.com/flickrviewer&lt;/a&gt; and live URL is &lt;a href="http://flickrmvc.net"&gt;http://flickrmvc.net&lt;/a&gt;.&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f05%2f31%2fflickr-web-app-with-mvc-preview-3-cont.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f05%2f31%2fflickr-web-app-with-mvc-preview-3-cont.aspx" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6236287" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LinqExtender/default.aspx">LinqExtender</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Linq.Flickr/default.aspx">Linq.Flickr</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/asp.net/default.aspx">asp.net</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/MVC/default.aspx">MVC</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Ajax/default.aspx">Ajax</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/AspNetMvc/default.aspx">AspNetMvc</category></item><item><title>Flickr Xplorer - An Asp.net MVC photo app for Flickr</title><link>http://weblogs.asp.net/mehfuzh/archive/2008/05/27/flickr-viewer-an-asp-net-mvc-photo-app-for-flickr.aspx</link><pubDate>Mon, 26 May 2008 20:13:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6222819</guid><dc:creator>mehfuzh</dc:creator><slash:comments>18</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6222819</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6222819</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/05/27/flickr-viewer-an-asp-net-mvc-photo-app-for-flickr.aspx#comments</comments><description>&lt;P&gt;I have flushed out a little project at Codeplex called "Flickr Xplorer". Its a Flickr mesh up that lets you search(user, tag, text), jump into user photos, see popular and latest stream and moreover lets you browse the whole Flickr in hacked url way (url routing easy and rocking). The application is made on Asp.net MVC preview 3&amp;nbsp; and I have used my &lt;A href="http://www.codeplex.com/LINQFlickr" target=_blank mce_href="http://www.codeplex.com/LINQFlickr"&gt;LINQ.Flickr&lt;/A&gt; to communicate with Flickr. The project is an early stage, I will update with new features when possible and how you ask. You can use it as you like , host it to your server to make it a personal dashboard for your taken photos or use it for fast hand on for Asp.net MVC , mocking and of course how to use LINQ.Flickr API :-)&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/FlickerviewerAnAsp.netMVCapp_150D4/image_6.png" mce_href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/FlickerviewerAnAsp.netMVCapp_150D4/image_6.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=image src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/FlickerviewerAnAsp.netMVCapp_150D4/image_thumb_2.png" width=502 height=425 mce_src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/FlickerviewerAnAsp.netMVCapp_150D4/image_thumb_2.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;you can try out the demo here &lt;A title="MVC flickr Explorer" href="http://www.flickrxplorer.net/" target=_blank mce_href="http://www.flickrXplorer.net/"&gt;http://www.flickrXplorer.net/&lt;/A&gt; (sometimes service may be unavailable due to update pardon me for that). Currently, App is tested under IE 6 &amp;amp; 7, Firefox 2.0+, will update for other browsers as well.&lt;/P&gt;
&lt;P&gt;The location for the project&amp;nbsp; : &lt;A href="http://www.codeplex.com/flickrXplorer" target=_blank mce_href="http://www.codeplex.com/flickrXplorer"&gt;www.codeplex.com/flickrXplorer&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Finally, have fun the new open source Flickr app and ping me if you have any suggestion to make it more interesting.&lt;/P&gt;
&lt;P&gt;Enjoy!!&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000&gt;Updated on 29th May 2008 - Asp.net MVC preview 3&lt;/FONT&gt; &lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000&gt;Updated on 28th June 2008 - Restructured, renamed and added social features.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000&gt;Updated on Sep 29&amp;nbsp;2008 - Update to MVC 5, Please check for the newest updates in&amp;nbsp;source tab&amp;nbsp;and all are pushed to live.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f05%2f27%2fflickr-viewer-an-asp-net-mvc-photo-app-for-flickr.aspx" mce_href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f05%2f27%2fflickr-viewer-an-asp-net-mvc-photo-app-for-flickr.aspx"&gt;&lt;IMG border=0 alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f05%2f27%2fflickr-viewer-an-asp-net-mvc-photo-app-for-flickr.aspx" mce_src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f05%2f27%2fflickr-viewer-an-asp-net-mvc-photo-app-for-flickr.aspx"&gt;&lt;/A&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6222819" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Linq.Flickr/default.aspx">Linq.Flickr</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/asp.net/default.aspx">asp.net</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/MVC/default.aspx">MVC</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Ajax/default.aspx">Ajax</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/AspNetMvc/default.aspx">AspNetMvc</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/FlickrXplorer/default.aspx">FlickrXplorer</category></item><item><title>Mock HTTP layer to do complex tasks like uploading photo to Flickr</title><link>http://weblogs.asp.net/mehfuzh/archive/2008/05/06/mock-http-layer-to-do-complex-tasks-like-uploading-photo-to-flickr.aspx</link><pubDate>Tue, 06 May 2008 05:58:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6161511</guid><dc:creator>mehfuzh</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6161511</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6161511</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/05/06/mock-http-layer-to-do-complex-tasks-like-uploading-photo-to-flickr.aspx#comments</comments><description>&lt;P&gt;In this post, I will show how you can use Typemock to fake out complex HTTP POST like uploading photo in Flickr server. The example which will be shown here, gives a pretty much generic idea of faking out HTTP calls and gain access to the response stream for comparing result with original content.I have used, N-Unit along with Typemock which run thorough TMockRunner.exe to perform the mock test. &lt;/P&gt;
&lt;P&gt;To get started, let's see what is really cooking in &lt;EM&gt;PhotoRepository.Upload&lt;/EM&gt; in LINQ.Flickr which we are going to mock.&lt;/P&gt;&lt;A href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/MockHTTPlayertodocomplextaskslikeuploadi_107E/image6.png" mce_href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/MockHTTPlayertodocomplextaskslikeuploadi_107E/image6.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=468 alt=image src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/MockHTTPlayertodocomplextaskslikeuploadi_107E/image6_thumb.png" width=476 border=0 mce_src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/MockHTTPlayertodocomplextaskslikeuploadi_107E/image6_thumb.png"&gt;&lt;/A&gt; 
&lt;P&gt;To focus strictly on mocking,&amp;nbsp; I have removed non-mockable parts and blocked out sections to be mocked. These include the following&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;1. Mock calls to Authenticate.&lt;/P&gt;
&lt;P&gt;2. Get a mocked signature.&lt;/P&gt;
&lt;P&gt;3. Mock the HttpRequest object &lt;/P&gt;
&lt;P&gt;4. Get reference of the Stream so that Stream.Write&amp;nbsp; writes to our desired media rather to the original request stream.&lt;/P&gt;
&lt;P&gt;5. Create a Fake WebResponse object and marry it with Request.GetResponse&lt;/P&gt;
&lt;P&gt;6. Get reference of the response stream&amp;nbsp; that will be filled with data from local resource.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Staring off every mock should have a MockManager.init(). we can further check if it is initialized or not by MockManager.Isinitialized.I have moved the common mock statements to a separate class for LINQ.Flickr which I call FakeFlickrReposity. It takes in the type of repository and the returned object and it can be constructed by a simple &lt;EM&gt;using&lt;/EM&gt; block as it implements IDisposable.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;using&lt;/SPAN&gt; (FakeFlickrRepository&amp;lt;PhotoRepository, Photo&amp;gt; photoAddMock = 
&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; FakeFlickrRepository&amp;lt;PhotoRepository, Photo&amp;gt;()) 
{ 
   ... 
   ... 
}&lt;/PRE&gt;
&lt;P&gt;Inside it creates a Mock in its constructor of type PhotoRepository, the method of which(Also, its &lt;EM&gt;base&lt;/EM&gt;) to be mocked.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; FakeFlickrRepository()
{
    _mockRepository = MockManager.Mock&amp;lt;T&amp;gt;(Constructor.NotMocked);
}&lt;/PRE&gt;
&lt;P&gt;The Constructor.NotMocked, means that the initialization codes for PhotoRepository wont be skipped. In this case creating the interface mapping to endpoint, getting keys, paths, etc.Now, going into the test class of LINQ.Flickr for uploading photo, I have first created the Photo object that has stream reference of a file from local resource.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=rem&gt;//[Following block used in the full codeview at the bottom]&lt;/SPAN&gt;
Stream photoRes = 
GetResourceStream(&lt;SPAN class=str&gt;"Linq.Flickr.Test.blank.gif"&lt;/SPAN&gt;); 
Photo photo = 
&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; Photo { Title = &lt;SPAN class=str&gt;"Flickr logo"&lt;/SPAN&gt;, FileName = &lt;SPAN class=str&gt;"Test.Mock"&lt;/SPAN&gt;,
File = photoRes, ViewMode = ViewMode.Public };&lt;/PRE&gt;
&lt;P&gt;Next, called the following &lt;/P&gt;&lt;PRE class=csharpcode&gt;photoAddMock.MockAuthenticateCall(&lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;, Permission.Delete);
photoAddMock.MockSignatureCall();&lt;/PRE&gt;
&lt;P&gt;Inside of &lt;EM&gt;MockAuthenticateCalls&lt;/EM&gt; looks like&lt;/P&gt;&lt;PRE class=csharpcode&gt;_mockRepository.
ExpectAndReturn(&lt;SPAN class=str&gt;"Authenticate"&lt;/SPAN&gt;, authToken)
.Args(validate, permission.ToString());&lt;/PRE&gt;
&lt;P&gt;And inside of &lt;EM&gt;MockSignatureCall&lt;/EM&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;_mockRepository.ExpectAndReturn(&lt;SPAN class=str&gt;"GetSignature"&lt;/SPAN&gt;, signature);&lt;/PRE&gt;
&lt;P&gt;ExpectAndReturn , as it looks like, traps a method call and returns the result right away rather going to the original flow. &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=csharpcode&gt;photoAddMock.FakeHttpRequestObject(fileStream);&lt;/PRE&gt;
&lt;P&gt;The above line is for faking HTTPWebRequest and get a stream reference out of it. Stepping in which we can see&lt;/P&gt;&lt;PRE class=csharpcode&gt;_httpRequestMock = MockManager.Mock(&lt;SPAN class=kwrd&gt;typeof&lt;/SPAN&gt;(HttpWebRequest)); A 
_httpRequestMock.ExpectSet(&lt;SPAN class=str&gt;"ContentType"&lt;/SPAN&gt;); B
_httpRequestMock.ExpectAndReturn(&lt;SPAN class=str&gt;"GetRequestStream"&lt;/SPAN&gt;, stream); C&lt;/PRE&gt;
&lt;P&gt;A =&amp;gt; Creates a mock of Type HttpWebRequest, B=&amp;gt; Sets an expectation of ContentType set, setting ContentType with mocked request will give a null reference as it depends on internal dictionary to do processing. C=&amp;gt; Sets an expection of GetRequestStream&amp;nbsp; and returns the reference to the stream provided from outside. &lt;/P&gt;&lt;PRE class=csharpcode&gt;photoAddMock.FakeWebResponse_GetResponse();&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will create a MockObject of type WebResponse class and will return a dummy instance of it when HttpRequest.GetResponse will be invoked.&lt;/P&gt;&lt;PRE class=csharpcode&gt;_webResponseMock = MockManager.MockObject&amp;lt;WebResponse&amp;gt;();
_httpRequestMock.ExpectAndReturn(&lt;SPAN class=str&gt;"GetResponse"&lt;/SPAN&gt;, _webResponseMock.Object);&lt;/PRE&gt;
&lt;P&gt;_httpRequestMock&amp;nbsp; is the private Mock variable that we created earlier. We also need to fill up the Response stream with proper Flickr response to be parsed by the LINQ.Flcikr system properly , in case of successful upload. To archive that, we need to marry our local resource stream to the &lt;EM&gt;WebResponse.GetResponStream&lt;/EM&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;_webResponseMock.
ExpectAndReturn(&lt;SPAN class=str&gt;"GetResponseStream"&lt;/SPAN&gt;, GetResourceStream(resource));
_webResponseMock.ExpectCall(&lt;SPAN class=str&gt;"Close"&lt;/SPAN&gt;);&lt;/PRE&gt;
&lt;P&gt;Finally, we need to make sure that response stream is closed properly. This is pretty much all which is to be mocked, the rest part of the code is to read the stream where the uploaded content is saved (pointed by us) and compare it with original photo binary. &lt;/P&gt;
&lt;P&gt;The part of the code is pasted here for more info of what I just said.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/MockHTTPlayertodocomplextaskslikeuploadi_107E/image_7.png" mce_href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/MockHTTPlayertodocomplextaskslikeuploadi_107E/image_7.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=656 alt=image src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/MockHTTPlayertodocomplextaskslikeuploadi_107E/image_thumb_2.png" width=390 border=0 mce_src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/MockHTTPlayertodocomplextaskslikeuploadi_107E/image_thumb_2.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;This whole implementation can be found at &lt;EM&gt;LINQ.Flickr.Test&lt;/EM&gt; under PhotoMockTest :: DoPhotoUploadAndDeleteTest, which can be downloaded from &lt;A href="http://www.codeplex.com/linqflickr" mce_href="http://www.codeplex.com/linqflickr"&gt;www.codeplex.com/linqflickr&lt;/A&gt;. Have a nice day!!&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f05%2f06%2fmock-http-layer-to-do-complex-tasks-like-uploading-photo-to-flickr.aspx" mce_href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f05%2f06%2fmock-http-layer-to-do-complex-tasks-like-uploading-photo-to-flickr.aspx"&gt;&lt;IMG alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f05%2f06%2fmock-http-layer-to-do-complex-tasks-like-uploading-photo-to-flickr.aspx" border=0 mce_src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f05%2f06%2fmock-http-layer-to-do-complex-tasks-like-uploading-photo-to-flickr.aspx"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;STYLE type=text/css&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6161511" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Linq.Flickr/default.aspx">Linq.Flickr</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/TypeMock/default.aspx">TypeMock</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Unit+Test/default.aspx">Unit Test</category></item><item><title>LINQ.Flickr 1.3</title><link>http://weblogs.asp.net/mehfuzh/archive/2008/05/05/linq-flickr-1-3.aspx</link><pubDate>Sun, 04 May 2008 19:33:02 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6157109</guid><dc:creator>mehfuzh</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6157109</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6157109</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/05/05/linq-flickr-1-3.aspx#comments</comments><description>&lt;p&gt;Just released another version of LINQ.Flickr. The release is out with several bug fixes, code optimization, new feature and overall mocking support. I have used Typemock for the unit test of the product. In coming posts, I will show how powerful mock can be in faking routine like upload photo. But, you can dig it right away, if you go by the release page and download a copy of the product. Truly speaking, testing was never fun for serviced API till mock engine is at my hand.&lt;/p&gt;  &lt;p&gt;The release is not all about re-factoring and mocking , but now you can query, add , delete photo comment , query people and popular tags and do more that are mentioned in the release page.&lt;/p&gt;  &lt;p&gt;Now, doing complex query is even more fun. lets take this.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;var query = from photo &lt;span class="kwrd"&gt;in&lt;/span&gt; _context.Photos
&lt;span class="kwrd"&gt;where&lt;/span&gt; photo.Id == photoId &amp;amp;&amp;amp; photo.PhotoSize == PhotoSize.Medium
select &lt;span class="kwrd"&gt;new&lt;/span&gt; FlickrPhoto
{
    Id = photo.Id,
    Description = photo.Description,
    Title = photo.Title,
    Url = photo.Url,
    User = photo.User,
    Comments = ((from comment &lt;span class="kwrd"&gt;in&lt;/span&gt; _context.Photos.Comments
                 &lt;span class="kwrd"&gt;where&lt;/span&gt; comment.PhotoId == photoId
                 select &lt;span class="kwrd"&gt;new&lt;/span&gt; PhotoComment
                 {
                     Author = comment.Author,
                     AuthorName = comment.AuthorName,
                     PermaLink = comment.PermaLink,
                     PhotoId = comment.PhotoId,
                     Text = comment.Text,
                 }).ToList&amp;lt;PhotoComment&amp;gt;()),
    Tags = photo.PhotoTags.Select(tag =&amp;gt; tag.Title).ToArray&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;()
};&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;FlickrPhoto newPhoto = query.Single();&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;The query is about getting the photo info for a specific photo id and I have now combined it with tags, comments to make it more useful. Also, few posts back, I have mentioned about using a RestToCollecitonBuilder&amp;#160; to build an object on REST response,&amp;#160; it is in action in this release as well.&lt;/p&gt;

&lt;p&gt;Finally, don't forget the link and it's &lt;a href="http://www.codeplex.com/linqflickr"&gt;www.codeplex.com/linqflickr&lt;/a&gt; . In the end, this project is not about querying Flickr and getting photo out of it, but it could be a great learning tool for Mocking, for building custom LINQ provider (with LinqExtender) and other things that you might need to know like, how to define a service endpoint by interface.&lt;/p&gt;

&lt;p&gt;Enjoy :-)&lt;/p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f05%2f05%2flinq-flickr-1-3.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f05%2f05%2flinq-flickr-1-3.aspx" border="0" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6157109" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Linq.Flickr/default.aspx">Linq.Flickr</category></item><item><title>Mocking static methods with Typemock</title><link>http://weblogs.asp.net/mehfuzh/archive/2008/04/21/mocking-static-methods-with-typemock.aspx</link><pubDate>Sun, 20 Apr 2008 21:37:01 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6116634</guid><dc:creator>mehfuzh</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6116634</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6116634</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/04/21/mocking-static-methods-with-typemock.aspx#comments</comments><description>&lt;p&gt;There are mocking tools like Rhino Mock, Moq, NMock, Typemock and many more. Recently, I was kinda evaluating mocking tools to mock out REST calls in Linq.Flickr. Almost all of the mock tools requires some sort of interface reference to work on. When, to mock out methods like XElement.Load or File.Open is impossible with most of the tools, Typemock is one step ahead of others as it supports mocking of static methods.&lt;/p&gt;  &lt;p&gt;Since, all the queries in Linq.Flickr goes through REST and all is tied with somehow with XElement.Load for getting the response in a LINQToXml fashion (I have mentioned already in my earlier posts, how :-)). I wanted to fake out the HTTP layer completely so that sitting in an airplane and with no Internet it is possible to test the product.&lt;/p&gt;  &lt;p&gt;Before going to any downloads , lets see how easy is Typemock in this regard.&lt;/p&gt;  &lt;p&gt;Now, all starts with a NUnit test class, where I have referenced the Typemock lib and during initialization of the test I faked out XElement.Load method for particular URL request to Flickr. Fragment of the code could be like&lt;/p&gt;  &lt;pre class="csharpcode"&gt;[SetUp]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Initialize()
{
   ...
   ...
   &lt;span class="rem"&gt;// initialize mock &lt;/span&gt;
    MockManager.Init();

    &lt;span class="kwrd"&gt;string&lt;/span&gt; frobUrl = &lt;span class="str"&gt;&amp;quot;http://api.flickr.com/services/rest/?       
    method=flickr.auth.getFrob&amp;amp;api_key=xxxx
    &amp;amp;api_sig=cdeb9a73a771d5ea374d014680b33a0e&amp;quot;&lt;/span&gt;;
    &lt;span class="rem"&gt;// custom method to get element locally&lt;/span&gt;
    XElement element1 = MockElement(frobUrl, &lt;span class="str"&gt;&amp;quot;LinqToFlickrTest.GetFrob.xml&amp;quot;&lt;/span&gt;); 
    &lt;span class="rem"&gt;// create the mock object.&lt;/span&gt;
    Mock mock1 = MockManager.Mock(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(XElement));
    mock1.ExpectAndReturn(&lt;span class="str"&gt;&amp;quot;Load&amp;quot;&lt;/span&gt;, element1).When(frobUrl);
   ...
   ...
}&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;So, I created a mock object of Type XElement and set it up for an URL so that when request comes in, it will return my response instead of looking into the sky for it. Finally, its all plain old test class, with no suspicious code :-)&lt;/p&gt;

&lt;pre class="csharpcode"&gt;[Test]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Test()
{
    var query = from photo &lt;span class="kwrd"&gt;in&lt;/span&gt; _context.Photos
                &lt;span class="kwrd"&gt;where&lt;/span&gt; photo.SearchMode == SearchMode.TagsOnly 
                &amp;amp;&amp;amp; photo.SearchText == &lt;span class="str"&gt;&amp;quot;microsoft&amp;quot;&lt;/span&gt;
                select photo; 

    &lt;span class="kwrd"&gt;int&lt;/span&gt; count = query.Count(); 
   ...
   ...
}&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Additionally, its nice to check if all the mock worked out fine in &lt;em&gt;TearDown by MockManager.Verify&lt;/em&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;[TearDown]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Verify()
{
    MockManager.Verify();
}&lt;/pre&gt;

&lt;p&gt;That's it , you can download a working sample &lt;a href="http://weblogs.asp.net/blogs/mehfuzh/LinqFlickrTest(Mock).zip" target="_blank"&gt;right here&lt;/a&gt;. If you have Typemock and NUnit installed, I have provided a .BAT for running NUnit through TMockRunner, change the paths accordingly to have it work for you.&lt;/p&gt;

&lt;p&gt;In the end, it is worth mentioning that currently Mock.&lt;em&gt;When &lt;/em&gt;is only supported in Typemock enterprise edition.Therefore, I will also wrap the dateaccess layer of &lt;a href="http://www.codeplex.com/LINQFlickr/" target="_blank"&gt;Linq.Flickr&lt;/a&gt; with interface reference so that it is possible to mock with others mocking tools as well and I will keep the code updated with latest changes so that you can play around it.&lt;/p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f04%2f21%2fmocking-static-methods-with-typemock.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f04%2f21%2fmocking-static-methods-with-typemock.aspx" border="0" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6116634" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Linq.Flickr/default.aspx">Linq.Flickr</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LINQ+To+Xml/default.aspx">LINQ To Xml</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/TypeMock/default.aspx">TypeMock</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Unit+Test/default.aspx">Unit Test</category></item><item><title>LINQ.Flickr 1.2</title><link>http://weblogs.asp.net/mehfuzh/archive/2008/02/28/linq-flickr-1-2.aspx</link><pubDate>Wed, 27 Feb 2008 18:10:53 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5871475</guid><dc:creator>mehfuzh</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=5871475</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=5871475</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/02/28/linq-flickr-1-2.aspx#comments</comments><description>&lt;p&gt;Last week, I have released LINQ.Flickr 1.2 , this new release comes with some bugs fixes requested by community.&amp;nbsp; The best of them was not to be able to search only by user and with specific photo size. The bug started after converting it to use LinqExtender instead of its own query logic. So, now here it is&lt;/p&gt; &lt;p&gt;A complex query for getting 12 most recent photos for a user "neetulee" (my wife's photo stream, need to track what latest she uploads :-))&lt;/p&gt; &lt;p&gt;var query = (from ph &lt;span class="kwrd"&gt;in&lt;/span&gt; context.Photos&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;where&lt;/span&gt; ph.User == &lt;span class="str"&gt;"neetulee"&lt;/span&gt; &amp;amp;&amp;amp; ph.PhotoSize == PhotoSize.Square&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; orderby PhotoOrder.Date_Posted descending&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select ph).Take(12).Skip(0);&lt;/p&gt; &lt;p&gt;Also, I got request to have different config section for Flickr settings, which looks like&lt;/p&gt;&lt;pre class="csharpcode"&gt;&amp;lt;configSections&amp;gt;
    &amp;lt;section name=&lt;span class="str"&gt;"flickr"&lt;/span&gt;
 type=&lt;span class="str"&gt;"Linq.Flickr.Configuration.FlickrSettings, Linq.Flickr"&lt;/span&gt;/&amp;gt;
  &amp;lt;/configSections&amp;gt;

  &amp;lt;flickr apiKey=&lt;span class="str"&gt;"##Your API Key##"&lt;/span&gt; secretKey=&lt;span class="str"&gt;"##Your Secret Key##"&lt;/span&gt;/&amp;gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Finally, I have added a NUnit project to test out the API, I will soon come up with a local solution that mocks flickr request, it is really slow and time consuming to test against remote source (esp , when you have to upload, get photos).&lt;/p&gt;
&lt;p&gt;And, one thing that I sure forgot to mention the demo_app, that I have created on LINQ.Flickr , it is still work in progress and working on converting it to MVC with some more features that will give a good startup with LINQ.Flickr. I will keep posted when done :-)&lt;/p&gt;
&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/LINQ.Flickr1.2_14545/image_2.png"&gt;&lt;img height="387" alt="image" src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/LINQ.Flickr1.2_14545/image_thumb.png" width="485"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Overall, thanks to the community for outstanding support, I hope to have it in coming days.&lt;/p&gt;
&lt;p&gt;LINQ.Flickr project URL : &lt;a href="http://www.codeplex.com/linqflickr/"&gt;www.codeplex.com/linqflickr/&lt;/a&gt;&amp;nbsp; &lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f02%2f28%2flinq-flickr-1-2.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f02%2f28%2flinq-flickr-1-2.aspx" border="0"&gt;&lt;/a&gt; 
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5871475" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Linq.Flickr/default.aspx">Linq.Flickr</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/asp.net/default.aspx">asp.net</category></item><item><title>REST with LINQ to XML</title><link>http://weblogs.asp.net/mehfuzh/archive/2008/01/11/rest-with-linq-to-xml.aspx</link><pubDate>Fri, 11 Jan 2008 12:30:32 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5587927</guid><dc:creator>mehfuzh</dc:creator><slash:comments>10</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=5587927</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=5587927</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/01/11/rest-with-linq-to-xml.aspx#comments</comments><description>&lt;p&gt;With LINQ to XML, what I have learned so far, it's awesome, it is not only the first class concept of processing XML data, but also let you process a complex XML doc in the most simplest and readable way.&lt;/p&gt; &lt;p&gt;I have a project called, &lt;a href="http://www.codeplex.com/LINQFlickr"&gt;Linq.Flickr&lt;/a&gt; , and I often need to process&amp;nbsp; XML data for REST query.&lt;/p&gt; &lt;p&gt;To show a simple example of LINQ to XML, lets take a REST response from a Flickr method called &lt;em&gt;flickr.people.getUploadStatus &lt;/em&gt;and see how it is processed.&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;user&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="12037949754@N01"&lt;/span&gt; &lt;span class="attr"&gt;ispro&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;  
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;username&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Bees&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;username&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; 
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;bandwidth&lt;/span&gt; &lt;span class="attr"&gt;maxbytes&lt;/span&gt;&lt;span class="kwrd"&gt;="2147483648"&lt;/span&gt; &lt;span class="attr"&gt;maxkb&lt;/span&gt;&lt;span class="kwrd"&gt;="2097152"&lt;/span&gt; 
&lt;span class="attr"&gt;usedbytes&lt;/span&gt;&lt;span class="kwrd"&gt;="383724"&lt;/span&gt; &lt;span class="attr"&gt;usedkb&lt;/span&gt;&lt;span class="kwrd"&gt;="374"&lt;/span&gt; &lt;span class="attr"&gt;remainingbytes&lt;/span&gt;&lt;span class="kwrd"&gt;="2147099924"&lt;/span&gt; &lt;span class="attr"&gt;remainingkb&lt;/span&gt;&lt;span class="kwrd"&gt;="2096777"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;filesize&lt;/span&gt; &lt;span class="attr"&gt;maxbytes&lt;/span&gt;&lt;span class="kwrd"&gt;="10485760"&lt;/span&gt; &lt;span class="attr"&gt;maxkb&lt;/span&gt;&lt;span class="kwrd"&gt;="10240"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;sets&lt;/span&gt; &lt;span class="attr"&gt;created&lt;/span&gt;&lt;span class="kwrd"&gt;="27"&lt;/span&gt; &lt;span class="attr"&gt;remaining&lt;/span&gt;&lt;span class="kwrd"&gt;="lots"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;user&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Before .net 3.5. it could have been done by GetElementyByTagName("users") - &amp;gt; inside the while loop getting the element, reading value, storing it in private variables , going to next sibling and repeat, if nested , then take the first child and so forth. But , in .net 3.5 using LINQ , the translation is not only just like XML itself, moreover , in XElement.Load , we can directly pass the REST query string.&lt;/p&gt;
&lt;p&gt;So, Two, steps to do a REST with LINQ&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Build the URL and pass it to XElement.Load 
&lt;li&gt;Parse the response and take necessary actions.&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;For example, for the above XML, I wrote something like below, in PhotoRepository.cs, that does a selective parsing.&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;try&lt;/span&gt;
{  &lt;/pre&gt;&lt;pre class="csharpcode"&gt;    XElement element = GetElement(##REQUEST URL##);

    People people = (from p &lt;span class="kwrd"&gt;in&lt;/span&gt; element.Descendants(&lt;span class="str"&gt;"user"&lt;/span&gt;)
      select &lt;span class="kwrd"&gt;new&lt;/span&gt; People
      {
            Id = p.Attribute(&lt;span class="str"&gt;"id"&lt;/span&gt;).Value ?? &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty,
            IsPro =
            Convert.ToInt32(p.Attribute(&lt;span class="str"&gt;"ispro"&lt;/span&gt;).Value) == 0 ? &lt;span class="kwrd"&gt;false&lt;/span&gt; : &lt;span class="kwrd"&gt;true&lt;/span&gt;,
            BandWidth =
            (from b &lt;span class="kwrd"&gt;in&lt;/span&gt; element.Descendants(&lt;span class="str"&gt;"bandwidth"&lt;/span&gt;)
               select &lt;span class="kwrd"&gt;new&lt;/span&gt; BandWidth
                {
                      RemainingKB = 
                      Convert.ToInt32(b.Attribute(&lt;span class="str"&gt;"remainingkb"&lt;/span&gt;).Value),
                      UsedKB = Convert.ToInt32(b.Attribute(&lt;span class="str"&gt;"usedkb"&lt;/span&gt;).Value)
                 }).Single&amp;lt;BandWidth&amp;gt;()
               }).Single&amp;lt;People&amp;gt;();

    &lt;span class="kwrd"&gt;return&lt;/span&gt; people;
}
&lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
{
    &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ApplicationException("Could not process response", ex);
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Note :GetElement is a local method that does a XElement.Load, with some validation check.&lt;/p&gt;
&lt;p&gt;Here my Client-Side object looks like &lt;/p&gt;
&lt;p&gt;People&lt;br&gt;Id&lt;br&gt;IsPro&lt;br&gt;BandWidth&lt;br&gt;&amp;nbsp;&amp;nbsp; RemainingKB&lt;br&gt;&amp;nbsp;&amp;nbsp; UsedKB 
&lt;p&gt;The most interesting thing is, everything is done on the fly , no loop, no intermediate result tracking, no headache of sibling and first child.Overall, the code has a high point in terms of readability.&lt;/p&gt;
&lt;p&gt;Take that !!&lt;/p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f01%2f11%2frest-with-linq-to-xml.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f01%2f11%2frest-with-linq-to-xml.aspx" border="0"&gt;&lt;/a&gt; 
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5587927" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Linq.Flickr/default.aspx">Linq.Flickr</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LINQ+To+Xml/default.aspx">LINQ To Xml</category></item><item><title>LinqExtender 1.2 is out now</title><link>http://weblogs.asp.net/mehfuzh/archive/2007/12/25/linqextender-1-2-is-out-now.aspx</link><pubDate>Mon, 24 Dec 2007 20:31:25 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5497506</guid><dc:creator>mehfuzh</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=5497506</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=5497506</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2007/12/25/linqextender-1-2-is-out-now.aspx#comments</comments><description>&lt;p&gt;Since, the first release of LinqExtender, I found quite a bit download and feedback from community around. I did plenty of changes and tried to make it as simple as possible for&amp;nbsp; creating custom providers,&amp;nbsp; without knowing a bit of reflection and expression parsing of the core framework.&lt;/p&gt; &lt;p&gt;After the release , I was asked by people around , why do we need Linq , when we can do it by method calls, the answer is, Linq gives another level of abstraction to method call that enables you to set a query domain for developers, by means of strongly type query objects, it's not like exposing the data access layer to the front end developer, but it is like giving them a playground with proper boundary. In other words, front end developers now can query on some specific criteria&amp;nbsp; that we set by means of query object , still giving them a flexibility of functional programming.&lt;/p&gt; &lt;p&gt;Now on to the release 1.2. it has come with query info retrieval wrapper and some new features ,which could be useful while making custom providers.&lt;/p&gt; &lt;p&gt;I have mentioned in following post, how query data is delegated to &lt;u&gt;Process&lt;/u&gt; routine, that will be overridden in the custom provider that developer is working on.&lt;/p&gt; &lt;p&gt;&lt;a title="http://weblogs.asp.net/mehfuzh/archive/2007/12/02/linqextender.aspx" href="http://weblogs.asp.net/mehfuzh/archive/2007/12/02/linqextender.aspx"&gt;http://weblogs.asp.net/mehfuzh/archive/2007/12/02/linqextender.aspx&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Now with new release it looks something like&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Process(LinqExtender.Interface.IModify&amp;lt;T&amp;gt; items, Bucket bucket)&lt;/pre&gt;
&lt;p&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
As , you can see that it has &lt;u&gt;Bucket&lt;/u&gt; object, which is nothing but a wrapper for holding the query details. Each Bucket has some BucketItem. BucketItem contains info for each property used in the expression&amp;nbsp; separated by &amp;amp;&amp;amp;.&lt;/p&gt;
&lt;p&gt;Typically &lt;u&gt;BucketItem&lt;/u&gt; looks like&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;BucketItem&lt;/u&gt;&lt;br&gt;Name&lt;/strong&gt; - Property name, different if the used with OriginalFieldNameAttribute, or less it is same as property name. &lt;br&gt;&lt;strong&gt;Value&lt;/strong&gt; - value in the query , for which the property is compared. Default value, Null.&lt;br&gt;&lt;strong&gt;Unique&lt;/strong&gt; - True , if UniqueIdentifierAttribute or its inherited type is used on property.Here, one can Use UniqueIdentifierAttribute directly on property or can use any inherited form like, PrimaryKeyAttribute that inherits the UniqueIdentifierattribute, to reflect value to this property.&lt;br&gt;&lt;strong&gt;RelationType&lt;/strong&gt; : Enum - Equal , LessThan, LessThatEqual, GreaterThan, GreaterThanEqual. Used to identify which type of logical comparison is used.&lt;/p&gt;
&lt;p&gt;Any of the property, which is not used in a query , BucketItem.Value and BucketItem.RelationType will have the default value for it, which is Null and Equal respectively.&lt;/p&gt;
&lt;p&gt;Now, Going Back to Bucket, it looks like&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;Bucket&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;&lt;strong&gt;IDictionary&amp;lt;string, BucketItem&amp;gt; Items&lt;/strong&gt; - List of items for property,&amp;nbsp; where &lt;u&gt;string&lt;/u&gt; is the property name of the query object, BuckItem represents how the Property is treated and used in query. &lt;br&gt;&lt;strong&gt;ItemsToTake&lt;/strong&gt; - default null , if &lt;u&gt;Take&lt;/u&gt; is not specified in query.&lt;br&gt;&lt;strong&gt;ItemsToTake&lt;/strong&gt; - default 0, if &lt;u&gt;Skip&lt;/u&gt; is not specified in query.&lt;br&gt;&lt;strong&gt;UniqueItems&lt;/strong&gt; - string[], contains the name of property on which UniqueIdentifierAttribute or its derivative is applied. 
&lt;p&gt;As, we can see from this release that Linqextender supports most common logical expression rather than just Equal expression. 
&lt;p&gt;The new release also supports&amp;nbsp; "New Type" queries, which i already mentioned in this post 
&lt;p&gt;&lt;a title="http://weblogs.asp.net/mehfuzh/archive/2007/12/16/anonymous-type-in-linqextender.aspx" href="http://weblogs.asp.net/mehfuzh/archive/2007/12/16/anonymous-type-in-linqextender.aspx"&gt;http://weblogs.asp.net/mehfuzh/archive/2007/12/16/anonymous-type-in-linqextender.aspx&lt;/a&gt; 
&lt;p&gt;Finally, I have added CTE(Common table expression) generation for OpenLinqToSql (Formerly known as TinyLinqToSql) provider. 
&lt;p&gt;Now , queries like the following with Take and Skip&lt;pre class="csharpcode"&gt;SqlQuery&amp;lt;Book&amp;gt; context = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlQuery&amp;lt;Book&amp;gt;();&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;var query = (from q &lt;span class="kwrd"&gt;in&lt;/span&gt; _queryContext
             orderby q.LastUpdated ascending
             select q).Take(5).Skip(2);&lt;/pre&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;// this is where the query will execute&lt;/span&gt;
&lt;span class="kwrd"&gt;foreach&lt;/span&gt;(var book &lt;span class="kwrd"&gt;in&lt;/span&gt; query)
{
 &lt;span class="rem"&gt;// do something useful &lt;/span&gt;
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Will generate Sql like...&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;WITH&lt;/span&gt; FilteredList(Id,Author,Title,ISBN,LastUpdated, [RowNumber]) &lt;span class="kwrd"&gt;AS&lt;/span&gt;(
&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; Id,Author,Title,ISBN,LastUpdated, Row_number()&lt;span class="kwrd"&gt;OVER&lt;/span&gt;(&lt;span class="kwrd"&gt;ORDER&lt;/span&gt; &lt;span class="kwrd"&gt;BY&lt;/span&gt; 
LastUpdated &lt;span class="kwrd"&gt;asc&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; [RowNumber] &lt;span class="kwrd"&gt;FROM&lt;/span&gt; Book 
)&lt;span class="kwrd"&gt;Select&lt;/span&gt; * &lt;span class="kwrd"&gt;from&lt;/span&gt; FilteredList &lt;span class="kwrd"&gt;WHERE&lt;/span&gt; [Rownumber] &lt;span class="kwrd"&gt;Between&lt;/span&gt; (3) &lt;span class="kwrd"&gt;and&lt;/span&gt; (7)&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Here, Take(5), Skip(2), it will take 5 items starting from 3.&lt;/p&gt;
&lt;p&gt;For more, I would suggest to have a look at release page of &lt;a href="http://www.codeplex.com/LINQExtender"&gt;LinqExtender&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;OpenLinqToSql provider is made to exercise the LinqExtender engine , it is provided with the LinqExtender source and with NUnit test class in LinqExtender project itself. There is another project named &lt;a href="http://www.codeplex.com/LINQFlickr"&gt;Linq.Flickr&lt;/a&gt;, where I have originally started working on with Linq provider and then made LinqExtender, this is currently a separate project. This shows another&amp;nbsp; possible implementation of LinqExtender, for service end points.&lt;/p&gt;
&lt;p&gt;Happy Holidays!!!&lt;/p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2007%2f12%2f25%2flinqextender-1-2-is-out-now.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2007%2f12%2f25%2flinqextender-1-2-is-out-now.aspx" border="0"&gt;&lt;/a&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5497506" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LinqExtender/default.aspx">LinqExtender</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Linq.Flickr/default.aspx">Linq.Flickr</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/OpenLinqToSql/default.aspx">OpenLinqToSql</category></item><item><title>Anonymous Type in LinqExtender</title><link>http://weblogs.asp.net/mehfuzh/archive/2007/12/16/anonymous-type-in-linqextender.aspx</link><pubDate>Sun, 16 Dec 2007 16:55:18 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5461957</guid><dc:creator>mehfuzh</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=5461957</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=5461957</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2007/12/16/anonymous-type-in-linqextender.aspx#comments</comments><description>&lt;p&gt;It is now possible for LinqExtender implemented providers to have anonymous type in the select query.&lt;/p&gt; &lt;p&gt;For example, consider the following&lt;/p&gt;&lt;pre class="csharpcode"&gt;SqlContext&amp;lt;Book&amp;gt; context = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlContext&amp;lt;Book&amp;gt;();

var query = (from q &lt;span class="kwrd"&gt;in&lt;/span&gt; context
            orderby q.LastUpdated descending
            select &lt;span class="kwrd"&gt;new&lt;/span&gt; { q.ISBN, q.Title}).Take(1);

var book = query.single();

&lt;span class="rem"&gt;// do something useful&lt;/span&gt;

Console.WriteLine (book.ISBN   + &lt;span class="str"&gt;"  "&lt;/span&gt; + book.Title);
&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;This sample done using TinyLinqToSql custom provider made on LinqExtender. Here I have some books in database and i want the top 1 , latest book out of it, also I need only two items, ISBN and Title, which I just need to show to in my current scope, without declaring any formal type, in this case the anonymous type can be useful and can be done in the above way. &lt;/p&gt;
&lt;p&gt;By the time , I am writing this post , I was having some problem with codeplex , for uploading the latest code of LinqExtender. Hope , it will be done , when you are reading this post.&lt;/p&gt;
&lt;p&gt;Also, I have uploaded a new version Linq.Flickr , with latest LinqExtender, so you can have the taste of anonymous type in there as well. Though this is out of scope of the post, but need to say that, now you can get photos with order by Date_Posted/ Date_Taken&amp;nbsp; asc/dsc respectively. Flickr API also supports, other two properties Relevance and Interestingness, but these two only support sort by ascending , therefore , I omitted this half feature, hope they will come with both way order for these two parameters.&lt;/p&gt;
&lt;p&gt;No need to say, you can download Linq.Flickr at &lt;a href="http://www.codeplex.com/linqflickr"&gt;www.codeplex.com/linqflickr&lt;/a&gt; and LinqExtender and TinyLinqToSql at &lt;a href="http://www.codeplex.com/linqextender"&gt;www.codeplex.com/linqextender&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Also, I found this cool post of Scott Gutherie for anonymous type, you might need to look at it as well.&lt;/p&gt;
&lt;p&gt;&lt;a title="http://weblogs.asp.net/scottgu/archive/2007/05/15/new-orcas-language-feature-anonymous-types.aspx" href="http://weblogs.asp.net/scottgu/archive/2007/05/15/new-orcas-language-feature-anonymous-types.aspx"&gt;http://weblogs.asp.net/scottgu/archive/2007/05/15/new-orcas-language-feature-anonymous-types.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Finally, an anon but cool guy from community named Reski Mills helped me implement this anon type real fast, thanks man!&lt;/p&gt;
&lt;p&gt;Enjoy!!&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2007%2f12%2f16%2fanonymous-type-in-linqextender.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2007%2f12%2f16%2fanonymous-type-in-linqextender.aspx" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5461957" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LinqExtender/default.aspx">LinqExtender</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Linq.Flickr/default.aspx">Linq.Flickr</category></item></channel></rss>