<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Mehfuz's WebLog</title><link>http://weblogs.asp.net/mehfuzh/default.aspx</link><description>Dont be a borg, harvest ideas and let your creativity shine.</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><creativeCommons:license>http://creativecommons.org/licenses/by/2.0/</creativeCommons:license><image><link>http://creativecommons.org/licenses/by/2.0/</link><url>http://creativecommons.org/images/public/somerights20.gif</url><title>Some Rights Reserved</title></image><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/burncsharp" type="application/rss+xml" /><feedburner:emailServiceId>burncsharp</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2Fburncsharp" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fburncsharp" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2Fburncsharp" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/burncsharp" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fburncsharp" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fburncsharp" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.yourminis.com/subscribe.aspx?u=http%3A%2F%2Ffeeds.feedburner.com%2Fburncsharp" src="http://www.yourminis.com/images/addtoyourminisbadge.gif">Subscribe with Yourminis.com</feedburner:feedFlare><feedburner:feedFlare href="http://www.flurry.com/pushRssFeed.do?r=fb&amp;url=http%3A%2F%2Ffeeds.feedburner.com%2Fburncsharp" src="http://www.flurry.com/images/flurry_rss_logo2.gif">Subscribe with Flurry</feedburner:feedFlare><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item><title>Operation could destabilize the runtime – Reflection.Emit and common pitfalls</title><link>http://feedproxy.google.com/~r/burncsharp/~3/2MFAtbBnT64/operation-could-destabilize-the-runtime-reflection-emit-and-common-pitfalls.aspx</link><pubDate>Sun, 07 Jun 2009 09:14:43 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7111205</guid><dc:creator>mehfuzh</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=7111205</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=7111205</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2009/06/07/operation-could-destabilize-the-runtime-reflection-emit-and-common-pitfalls.aspx#comments</comments><description>&lt;p&gt;In the last post i said about LinqtExtender implementing necessary property and injecting specific settings for entity objects. The issue i have is that it works fine under full / high trust settings but when running in medium trust it gives the following error:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Operationcoulddest.Emitandcommonpitfalls_C63B/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Operationcoulddest.Emitandcommonpitfalls_C63B/image_thumb.png" width="484" height="300" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Ouch.. it is only happening while i am using the extender from medium trust environment. As to add a little prologue, actually it creates a proxy around your original entity and if you look closely it is giving the error in &lt;strong&gt;.ctor()&lt;/strong&gt;. Now lets dig in.&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; ILGenerator ilGenerator = constructorBuilder.GetILGenerator();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt; ConstructorInfo baseConstructor = &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;).GetConstructors()[0];&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt; ilGenerator.Emit(OpCodes.Ldarg_0);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt; ilGenerator.Emit(OpCodes.Call, baseConstructor);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt; ilGenerator.Emit(OpCodes.Ret);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The IL code is pretty simple actually , its the method body of the proxy class constructor that calls default constructor of the base class. Now, this will work fine in full/high trust as here i require the entity class to have a default constructor. But, as i switch the mode to medium trust it will throw me the above exception. The reason why, in medium trust the framework verifies the IL generated and though it may seem from my point of view that its a valid IL as it is expecting default constructor , to framework’s context its invalid as the base object might never have any default constructor (it should throw error in high trust). In that case the call is absolutely suspicious duh…&lt;/p&gt;

&lt;p&gt;So the valid block for this scenario would be:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; ILGenerator ilGenerator = constructorBuilder.GetILGenerator();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt; ConstructorInfo baseConstructor = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt; ConstructorInfo[] constructorInfos = parent.GetConstructors();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; containsDefaultConstructor = &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (ConstructorInfo info &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; constructorInfos)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (info.GetParameters().Length == 0)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt;  12:&lt;/span&gt;         baseConstructor = info;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum13"&gt;  13:&lt;/span&gt;         containsDefaultConstructor = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum14"&gt;  14:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum15"&gt;  15:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum16"&gt;  16:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum17"&gt;  17:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum18"&gt;  18:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!containsDefaultConstructor)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum19"&gt;  19:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Exception(Properties.Messages.MustHaveADefaultConstructor);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum20"&gt;  20:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum21"&gt;  21:&lt;/span&gt; ilGenerator.Emit(OpCodes.Ldarg_0);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum22"&gt;  22:&lt;/span&gt; ilGenerator.Emit(OpCodes.Call, baseConstructor);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum23"&gt;  23:&lt;/span&gt; ilGenerator.Emit(OpCodes.Ret);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The code is similar , just it checks for a default constructor , if not throws a valid exception and to medium trust everything looks fine.&amp;#160; I have added a patch for extender with this as well, do check it out.&lt;/p&gt;

&lt;p&gt;Finally, while you are doing &lt;em&gt;Reflection.Emit&lt;/em&gt; do check this and more like, you should not emit any unmanaged code and even not play around with private stuffs , etc to avoid pitfalls.&lt;/p&gt;

&lt;p&gt;Hope that helps&lt;/p&gt;
&lt;a href="http://dotnetshoutout.com/Operation-could-destabilize-the-runtime-ReflectionEmit-and-common-pitfalls-Mehfuzs-WebLog" rev="vote-for"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fmehfuzh%2Farchive%2F2009%2F06%2F07%2Foperation-could-destabilize-the-runtime-reflection-emit-and-common-pitfalls.aspx" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7111205" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=2MFAtbBnT64:gMqzfEZmGX8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=2MFAtbBnT64:gMqzfEZmGX8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=2MFAtbBnT64:gMqzfEZmGX8:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=2MFAtbBnT64:gMqzfEZmGX8:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?i=2MFAtbBnT64:gMqzfEZmGX8:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/2MFAtbBnT64" height="1" width="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/MSIL/default.aspx">MSIL</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2009/06/07/operation-could-destabilize-the-runtime-reflection-emit-and-common-pitfalls.aspx</feedburner:origLink></item><item><title>Extending your existing API or legacy data classes to support LINQ</title><link>http://feedproxy.google.com/~r/burncsharp/~3/yIsfNSpqn20/extending-your-existing-api-or-legacy-data-classes-to-support-linq.aspx</link><pubDate>Sat, 06 Jun 2009 08:10:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7109480</guid><dc:creator>mehfuzh</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=7109480</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=7109480</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2009/06/06/extending-your-existing-api-or-legacy-data-classes-to-support-linq.aspx#comments</comments><description>&lt;P&gt;While developing LinqExtender, i have come across various scenarios that people don’t want to extent any query class or even implement any interface. Also, it is almost absurd when they have to add new extender specific attributes to their entity class. It is though not very important for people creating new provider with small codebase but with large codebase it soon becomes a pain to modify each class.&lt;/P&gt;
&lt;P&gt;The solution is to make Extender as a container , which is people will write their logic to act on their specific entity or list of entities, also define their settings via fluent interface. To wrap it around , there is a basic ORM that comes with the extender pack and i have a made LibraryContext on top of SqlQueryContext&amp;lt;T&amp;gt;. Inside, the constructor i wrote the following code to define the extender specific settings.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id=codeSnippetWrapper&gt;
&lt;DIV style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px" id=codeSnippet&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum1&gt;   1:&lt;/SPAN&gt; Extender&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum2&gt;   2:&lt;/SPAN&gt;     .Settings&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum3&gt;   3:&lt;/SPAN&gt;         .For&amp;lt;Base&amp;gt;()&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum4&gt;   4:&lt;/SPAN&gt;         .Begin&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum5&gt;   5:&lt;/SPAN&gt;             .Property(x =&amp;gt; x.Id).MarkAsUnique&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum6&gt;   6:&lt;/SPAN&gt;         .End&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum7&gt;   7:&lt;/SPAN&gt;         .For&amp;lt;Book&amp;gt;()&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum8&gt;   8:&lt;/SPAN&gt;         .MapToEntity(&lt;SPAN style="COLOR: #006080"&gt;"book"&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum9&gt;   9:&lt;/SPAN&gt;         .Begin&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum10&gt;  10:&lt;/SPAN&gt;             .Property(x =&amp;gt; x.Id).MapToAttribute(&lt;SPAN style="COLOR: #006080"&gt;"Bk_Id"&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum11&gt;  11:&lt;/SPAN&gt;             .Property(x =&amp;gt; x.ShelveId).MapToAttribute(&lt;SPAN style="COLOR: #006080"&gt;"Shelve_Id"&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum12&gt;  12:&lt;/SPAN&gt;             .Property(x =&amp;gt; x.Title).MapToAttribute(&lt;SPAN style="COLOR: #006080"&gt;"Bk_Title"&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum13&gt;  13:&lt;/SPAN&gt;             .Property(x =&amp;gt; x.BookInfo).MarkToIgnore()&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum14&gt;  14:&lt;/SPAN&gt;         .End&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum15&gt;  15:&lt;/SPAN&gt;         .For&amp;lt;Library&amp;gt;()&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum16&gt;  16:&lt;/SPAN&gt;         .MapToEntity(&lt;SPAN style="COLOR: #006080"&gt;"Bk_Library"&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum17&gt;  17:&lt;/SPAN&gt;     .InstantiateIn(&lt;SPAN style="COLOR: #0000ff"&gt;this&lt;/SPAN&gt;);    &lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;Note that there is a &lt;EM&gt;base &lt;/EM&gt;settings that will be applied to all the common properties under my project and is a local class inherited from LinqExtender.Configruation.All. During the instantiation it will be applied to the current container instance.&lt;/P&gt;
&lt;P&gt;Now, as i have said extender should be used a container so that there should be no strings attached. In my entity class, i can implement IQueryObject to mark it as a query class, but if not then extender should be smarter enough to implement it internally when the entity is used in LINQ query via extender query class. Actually , under the hood it dynamically creates a proxy via &lt;EM&gt;Reflection.Emit&lt;/EM&gt; that has the settings and ensures &lt;EM&gt;IQueryObject. &lt;/EM&gt;I will in days time come out with a open source project where i have practiced all these reflection stuffs and which i will extensively blog about , so stay tuned.&lt;/P&gt;
&lt;P&gt;To make it more clear i have re-implemented the LINQ to Twitter post using the new extender. So few things like implementing IQueryObject and defining unique identifier is no longer required. You can get the new copy at the end of the post.&lt;STRIKE&gt; Also, before i forget, there is a tiny catch which is you can’t left the extender auto generate settings, if you are using it in medium-trust as &lt;EM&gt;Reflection.Emit&lt;/EM&gt; does not work in such environment. In that case you will have to implement IQueryObject by hand and add the attributes manually to make it work so i am leaving LinqToTwitter post untouched &lt;/STRIKE&gt;[See bottom]. I know most of the good hosting providers these days support high trust and soon i think medium trust will become classic with dynamic proxy generation and cross domain request is becoming growing common (Just my two cents, don't want to get in war with these ;)).&lt;/P&gt;
&lt;P&gt;In previous release you can access the Fluent implementation of Bucket just by &lt;EM&gt;Bucket.Instance&lt;/EM&gt;, as it seems that i have somewhere statically stored the bucket object and the syntax bit more sexy but considering multiple threads , there is a possibility of data corruption. Therefore Bucket instance is passed to Query&amp;lt;T&amp;gt; overrides as IBucket and new syntax for Bucket.Instance follows&lt;/P&gt;
&lt;DIV id=codeSnippetWrapper&gt;
&lt;DIV style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px" id=codeSnippet&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum1&gt;   1:&lt;/SPAN&gt; FluentBucket fluentBucket = FluentBucket.As(bucket);&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum2&gt;   2:&lt;/SPAN&gt; // &lt;SPAN style="COLOR: #0000ff"&gt;do&lt;/SPAN&gt; your work.&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;Down to acknowledgement , Microsoft Germany has published two new tutorials around LinqExtender using LinqToFlickr and LinqToTwitter that also led me fix the VB method call issue and thanks Lars and Tim. In German way i would say, “Danke[Dang – ko]”. You can find the recordings in the following URLs&lt;/P&gt;
&lt;P&gt;&lt;A title=http://www.microsoft.com/germany/msdn/solve/codeclips/library.aspx?id=msdn_de_33389 href="http://www.microsoft.com/germany/msdn/solve/codeclips/library.aspx?id=msdn_de_33389" target=_blank mce_href="http://www.microsoft.com/germany/msdn/solve/codeclips/library.aspx?id=msdn_de_33389"&gt;http://www.microsoft.com/germany/msdn/solve/codeclips/library.aspx?id=msdn_de_33389&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A title=http://www.microsoft.com/germany/msdn/solve/codeclips/library.aspx?id=msdn_de_33369 href="http://www.microsoft.com/germany/msdn/solve/codeclips/library.aspx?id=msdn_de_33369" target=_blank mce_href="http://www.microsoft.com/germany/msdn/solve/codeclips/library.aspx?id=msdn_de_33369"&gt;http://www.microsoft.com/germany/msdn/solve/codeclips/library.aspx?id=msdn_de_33369&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Finally, while we are preparing our new Sitefinity release and making some LINQ extensions, bob’s comments were helpful&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;shaping the release as well and nonetheless all community reviews and feedbacks are great. Try the new release &lt;A href="http://linqextender.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=28187" target=_blank mce_href="http://linqextender.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=28187"&gt;&lt;STRONG&gt;here&lt;/STRONG&gt;&lt;/A&gt;.&lt;/P&gt;
&lt;DIV style="PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; DISPLAY: inline; FLOAT: none; PADDING-TOP: 0px" id=scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:ebe9906b-88ef-4dc9-bde1-fb6c0ca499c9 class=wlWriterEditableSmartContent&gt;
&lt;DIV&gt;Linq To Twitter Source : &lt;A href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/ExtendingyourexistingAPIorlegacydataclas_B075/LinqToTwitter_1.zip" target=_blank mce_href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/ExtendingyourexistingAPIorlegacydataclas_B075/LinqToTwitter_1.zip"&gt;LinqToTwitter.zip&lt;/A&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;Enjoy !!!&lt;/P&gt;
&lt;P&gt;June 7, 2009 =&amp;gt; Correction ,&lt;EM&gt;Reflecton.Emit&lt;/EM&gt; does not&amp;nbsp;work in medium trust for unmanaged IL codes&amp;nbsp;and&amp;nbsp; possible IL that might destabilize the runtime that it finds by verifying the assembly, will show more on it in upcoming post.&amp;nbsp;Added a patch of extender, this will work in medium trust with auto implementaion and fluent configuration.&lt;/P&gt;&lt;A href="http://dotnetshoutout.com/Extending-your-existing-API-or-legacy-data-classes-to-support-LINQ-Mehfuzs-WebLog" rev=vote-for&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fmehfuzh%2Farchive%2F2009%2F06%2F06%2Fextending-your-existing-api-or-legacy-data-classes-to-support-linq.aspx"&gt;&lt;/A&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7109480" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=yIsfNSpqn20:Pn7xGJI424g:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=yIsfNSpqn20:Pn7xGJI424g:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=yIsfNSpqn20:Pn7xGJI424g:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=yIsfNSpqn20:Pn7xGJI424g:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?i=yIsfNSpqn20:Pn7xGJI424g:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/yIsfNSpqn20" height="1" width="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/LinqToTwitter/default.aspx">LinqToTwitter</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2009/06/06/extending-your-existing-api-or-legacy-data-classes-to-support-linq.aspx</feedburner:origLink></item><item><title>Using of JSON Result in Asp.net MVC 1.0</title><link>http://feedproxy.google.com/~r/burncsharp/~3/6oXALYrHsPI/using-of-json-result-in-asp-net-mvc-1-0.aspx</link><pubDate>Tue, 28 Apr 2009 09:20:50 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7063244</guid><dc:creator>mehfuzh</dc:creator><slash:comments>9</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=7063244</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=7063244</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2009/04/28/using-of-json-result-in-asp-net-mvc-1-0.aspx#comments</comments><description>&lt;p&gt;In a post few month back , i showed how can i simulate a callback using JQuery and ASP.NET with my experimental FlickrXplorer project. More detail on this can be found at the following URL&lt;/p&gt;  &lt;p&gt;&lt;a title="http://weblogs.asp.net/mehfuzh/archive/2008/10/13/using-jquery-to-do-ajax-form-posts-in-asp-net-mvc.aspx" href="http://weblogs.asp.net/mehfuzh/archive/2008/10/13/using-jquery-to-do-ajax-form-posts-in-asp-net-mvc.aspx" target="_blank"&gt;http://weblogs.asp.net/mehfuzh/archive/2008/10/13/using-jquery-to-do-ajax-form-posts-in-asp-net-mvc.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now, what i have done here is basically, i did an AJAX call to the controller and rendered the view result in a div.&amp;#160; One thing about this way is that i am able to make the view strongly typed as i first rendered view using standard way with all the strongly type ViewData.Model. It is nice for rendering views with small amount of html in it (Like , tag lists), but slow for big outputs. The best practice for all these is to use the JSONResult. Here, i will show a small example of how i render the comment list in FlickrXplorer using JSON result and JQuery $.get in conjunction to make the AJAX request.&lt;/p&gt;  &lt;p&gt;First, let’s see how the controller looks like. Assume that there is a controller named &lt;em&gt;CommentController&lt;/em&gt; and we have an action named &lt;em&gt;List&lt;/em&gt;&lt;/p&gt;  &lt;pre class="csharpcode"&gt;[AcceptVerbs(HttpVerbs.Get)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult List(&lt;span class="kwrd"&gt;string&lt;/span&gt; photoId, &lt;span class="kwrd"&gt;int&lt;/span&gt; ? index, &lt;span class="kwrd"&gt;int&lt;/span&gt;? page)
{
    &lt;span class="kwrd"&gt;int&lt;/span&gt; skip = index == &lt;span class="kwrd"&gt;null&lt;/span&gt; ? 0 : index.Value*page.Value;
    &lt;span class="kwrd"&gt;int&lt;/span&gt; take = page == &lt;span class="kwrd"&gt;null&lt;/span&gt; ? &lt;span class="kwrd"&gt;int&lt;/span&gt;.MaxValue : page.Value;

    PhotoCommentViewData comments = &lt;span class="kwrd"&gt;new&lt;/span&gt; PhotoCommentViewData();

    &lt;span class="kwrd"&gt;try&lt;/span&gt;
    {
        comments = model.GetComments(photoId, skip, take, &lt;span class="kwrd"&gt;false&lt;/span&gt;);
        &lt;span class="kwrd"&gt;return&lt;/span&gt; Json(comments);
    }
    &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
    {
         &lt;span class="rem"&gt;/// do some exception tracking&lt;/span&gt;
    }
}&lt;/pre&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;As it seems, it gets the list of comment from its underlying model and then pass it through &lt;strong&gt;JSON &lt;/strong&gt;result. Optionally, i limited that the action should only be accepting GET calls as it is a list request.&lt;/p&gt;

&lt;p&gt;Now, coming back to JavaScript we first need to do a GET request to this action and syntax for doing it in JQuery style:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;$.get(url, { index: index, page: page }, function(result) {

   processComments(url, result, &lt;strike&gt;index, page, loaderTarget, contentTarget&lt;/strike&gt;); [strike though is not covered in the post]

 }, &lt;span class="str"&gt;&amp;quot;json&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;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 first argument is the comment list URL, this is constructed in server side using &lt;strong&gt;Url.Action&lt;/strong&gt; and then passed in the JS that also ensures the routing setup, second is the JSON string for params, third is the callback for the result it fetches and final is the type of response it should contain.&lt;/p&gt;

&lt;p&gt;Inside &lt;strong&gt;&lt;em&gt;processComments &lt;/em&gt;,&lt;/strong&gt; i basically do some DOM operations to build the necessary html block&lt;/p&gt;

&lt;pre class="csharpcode"&gt;$(&lt;span class="str"&gt;&amp;quot;#layout&amp;quot;&lt;/span&gt;)
    .append($(&lt;span class="str"&gt;&amp;quot;&amp;lt;tr/&amp;gt;&amp;quot;&lt;/span&gt;)
        .css({&lt;span class="str"&gt;&lt;span class="str"&gt;'vertical-align' : 'top'&lt;/span&gt;&lt;/span&gt;})
        .append($(&lt;span class="str"&gt;&amp;quot;&amp;lt;td/&amp;gt;&amp;quot;&lt;/span&gt;)
        .attr(&lt;span class="str"&gt;&amp;quot;class&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;said&amp;quot;&lt;/span&gt;)
        .append($(&lt;span class="str"&gt;&amp;quot;&amp;lt;strong/&amp;gt;&amp;quot;&lt;/span&gt;)
        .append($(&lt;span class="str"&gt;&amp;quot;&amp;lt;a/&amp;gt;&amp;quot;&lt;/span&gt;)
                .attr(&lt;span class="str"&gt;&amp;quot;href&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;/Photo/NsId/&amp;quot;&lt;/span&gt; + comment.Author)
                .css({ &lt;span class="str"&gt;'color'&lt;/span&gt;: &lt;span class="str"&gt;'#0063DC'&lt;/span&gt;, &lt;span class="str"&gt;'text-decoration'&lt;/span&gt;: &lt;span class="str"&gt;'none'&lt;/span&gt;})
                .append(comment.AuthorName))
            .append(&lt;span class="str"&gt;&amp;quot;&amp;amp;nbsp;says: &amp;quot;&lt;/span&gt;))
        .append($(&lt;span class="str"&gt;&amp;quot;&amp;lt;br/&amp;gt;&amp;quot;&lt;/span&gt;))
        .append(comment.Text)));&lt;/pre&gt;

&lt;p&gt;So, there is a “layout” panel in the comment container where i am to add the dynamic html. jQuery has this nice way of adding html in a chain and elements under it. For example i want to render a html link with some custom CSS and i want to point that to some URL as well.&lt;/p&gt;

&lt;p&gt;Using jQuery , i would do&lt;/p&gt;

&lt;pre class="csharpcode"&gt;$(&lt;span class="str"&gt;&amp;quot;&amp;lt;a/&amp;gt;&amp;quot;&lt;/span&gt;)
 .attr(&lt;span class="str"&gt;&amp;quot;href&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;/Photo/NsId/&amp;quot;&lt;/span&gt; + comment.Author)
 .css({ &lt;span class="str"&gt;'color'&lt;/span&gt;: &lt;span class="str"&gt;'#0063DC'&lt;/span&gt;, &lt;span class="str"&gt;'text-decoration'&lt;/span&gt;: &lt;span class="str"&gt;'none'&lt;/span&gt; })
 .append(comment.AuthorName)&lt;/pre&gt;

&lt;p&gt;This will render a html tag something like&lt;/p&gt;

&lt;p&gt;&amp;lt;a href=”/photo/NsId/x@y” style=”color:#0063DC, text-decoration:none”&amp;gt;Mehfuz &amp;lt;/a&amp;gt;&lt;/p&gt;

&lt;p&gt;The rule is that you start a element with $(…) in XHTML style then add necessary attributes, styles and text and it will automatically give you a well-formed html,&amp;#160; moreover you can nest it as you like with other elements.&lt;/p&gt;

&lt;p&gt;The above block finally produces a look similar to&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/UsingofJSONResultinAsp.netMVC1.0_BFA5/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/UsingofJSONResultinAsp.netMVC1.0_BFA5/image_thumb.png" width="235" height="188" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;There are few other JS that&amp;#160; is responsible for generating the pager control which is not covered in this post, for this and more you can take a look at the latest bits of FlickrXplorer under &lt;a href="http://www.codeplex.com/flickrXplorer" target="_blank"&gt;www.codeplex.com/flickrXplorer&lt;/a&gt; .That’s so far and if you have some cool ideas to share on this,&amp;#160; let me know.&lt;/p&gt;

&lt;p&gt;Hope that helps.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://dotnetshoutout.com/Using-of-JSON-Result-in-Aspnet-MVC-10-Mehfuzs-WebLog" rev="vote-for"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fmehfuzh%2Farchive%2F2009%2F04%2F28%2Fusing-of-json-result-in-asp-net-mvc-1-0.aspx" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7063244" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=6oXALYrHsPI:OIEbeeQxdr0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=6oXALYrHsPI:OIEbeeQxdr0:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=6oXALYrHsPI:OIEbeeQxdr0:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=6oXALYrHsPI:OIEbeeQxdr0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?i=6oXALYrHsPI:OIEbeeQxdr0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/6oXALYrHsPI" height="1" width="1"/&gt;</description><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/AspNetMvc/default.aspx">AspNetMvc</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/jQuery/default.aspx">jQuery</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2009/04/28/using-of-json-result-in-asp-net-mvc-1-0.aspx</feedburner:origLink></item><item><title>Programmatically generating SQL(DDL) from M</title><link>http://feedproxy.google.com/~r/burncsharp/~3/L9xllO5FMM4/programmatically-generating-sql-ddl-from-m.aspx</link><pubDate>Mon, 30 Mar 2009 10:03:05 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7010618</guid><dc:creator>mehfuzh</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=7010618</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=7010618</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2009/03/30/programmatically-generating-sql-ddl-from-m.aspx#comments</comments><description>&lt;p&gt;In this post, i will show how you can generate SQL programmatically from M. Now, so far i have learnt that MGrammer is a contract that converts user’s input into MGraph. Now, Oslo by default comes with MSchema. Through MSchema you can define a type and extend it with MGraph to populate your repository. Here, i will use MSchema to define an entity object , then MGraph and finally run this through a custom SQL generator in C# to get my DDL statement similar to what you can generate by using intellipad that comes with Oslo SDK.&lt;/p&gt;  &lt;p&gt;Let’s define a Contacts M&lt;/p&gt;  &lt;pre class="csharpcode"&gt;module Contacts {
    type Person {
        Id : Integer32;
        Name: Text;
        Age: Integer32;
    } &lt;span class="kwrd"&gt;where&lt;/span&gt; identity Id;
    
    People : Person*
    {    
        {Id = 1, Name=&lt;span class="str"&gt;&amp;quot;Steve&amp;quot;&lt;/span&gt;,Age=36}, 
        {Id = 2, Name=&lt;span class="str"&gt;&amp;quot;Kazi&amp;quot;&lt;/span&gt;,Age=30}
    };
    Employee : Person*
    {    
        {Id = 1, Name=&lt;span class="str"&gt;&amp;quot;Nike&amp;quot;&lt;/span&gt;,Age=29} 
    };
}&lt;/pre&gt;

&lt;p&gt;So, “Person” is a type with ID,Name and Age respectively that is under “Contacts” module with two different MGraph which are “People” and “Employee” that will generate separate &lt;em&gt;create table&lt;/em&gt; statements of “Person” type.&lt;/p&gt;

&lt;p&gt;Internally , M is&amp;#160; represented somewhat like&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/image_3252AFCD.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/mehfuzh/image_thumb_7D65AA8F.png" width="238" height="170" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Parsing the M all starts with &lt;em&gt;Microsoft.M.Parser.SourceParser. &lt;/em&gt;In my sample M to SQL project, i used it like&lt;/p&gt;

&lt;pre class="csharpcode"&gt;SqlGenerator generator = SqlGenerator.Load(&lt;span class="kwrd"&gt;new&lt;/span&gt; StringReader(code));
&lt;span class="kwrd"&gt;string&lt;/span&gt; sql = generator.Generate();&lt;/pre&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;Inside Load…&lt;/p&gt;

&lt;pre class="csharpcode"&gt;SourceParser parser = &lt;span class="kwrd"&gt;new&lt;/span&gt; SourceParser();
syntaxTerm = (CompilationUnit)parser.ParseTerm(reader, &lt;span class="str"&gt;&amp;quot;buffer.m&amp;quot;&lt;/span&gt;);
...
...

&lt;span class="rem"&gt;/// check if the parse was successful&lt;/span&gt;
&lt;span class="kwrd"&gt;if&lt;/span&gt; (!parser.LastParseSuccessful)
{
    &lt;span class="rem"&gt;/// do some error processing for invalid schema.&lt;/span&gt;
}&lt;/pre&gt;

&lt;p&gt;Now, once we have a valid grammar, our next step is to get the modules from ISytaxTerm implementation, for each module we have to process the MGraph for the specified type.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (IModuleDeclaration declaration &lt;span class="kwrd"&gt;in&lt;/span&gt; syntaxTerm.Modules)
{
    builder.AppendSetExtactAbort();
    builder.AppendGo();

    builder.AppendBeginTransaction();
    builder.AppendGo();

    builder.AppendSetANSINulls();
    builder.AppendGo();

    builder.AppendCreateSchema(declaration.Name.Value);
    builder.AppendGo();
    &lt;strong&gt;builder.Append(ProcessMembers(declaration.Name.Value, declaration.Members));
&lt;/strong&gt;
    builder.AppendCommitTransaction();
    builder.AppendGo();
}&lt;/pre&gt;

&lt;p&gt;This shows the basic skeleton of how the output will look like. &lt;em&gt;ProcessMembers&lt;/em&gt; is the actual place that generates the entity from type and associates Insert statements. Only, during the MGraph initialization type is realized. Therefore, the table name is equal to the extent name not to the type name.&lt;/p&gt;

&lt;p&gt;Inside ProcessMembers …&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;pre class="csharpcode"&gt;&lt;span class="rem"&gt;/// There will be three declaration &lt;/span&gt;
&lt;span class="rem"&gt;/// -TypeDeclaion&lt;/span&gt;
&lt;span class="rem"&gt;///- ExtentDeclaration&lt;/span&gt;
&lt;span class="rem"&gt;///- ExtnetDeclaration&lt;/span&gt;
&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (IDeclaration declaration &lt;span class="kwrd"&gt;in&lt;/span&gt; declarations)
{
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (declaration &lt;span class="kwrd"&gt;is&lt;/span&gt; TypeDeclaration)
    {
        typeDeclaration = (TypeDeclaration) declaration;
    }
 
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (declaration &lt;span class="kwrd"&gt;is&lt;/span&gt; ExtentDeclaration)
    {
       &lt;span class="rem"&gt;/// use the type declaration from previous step.&lt;/span&gt;
        builder.Append(ProcessExtent(name, typeDeclaration, (ExtentDeclaration) declaration));
    }
}&lt;/pre&gt;

&lt;p&gt;TypeDeclaration is narrowed down to &lt;em&gt;ParameteriedExpression&lt;/em&gt; , which has different operations for the declaring type&lt;em&gt;, &lt;/em&gt;which is tracked by&amp;#160; DeclartionReference.Name (“$Operator$Where”, “$Operator$Identity” , etc). Therefore, to process constraint and data types separately, we need to switch them for operation type.&amp;#160; Now, the question is how the MGraph is referred from the type specified. The JSON like string&amp;#160; is basically translated to GraphExpression. Like for the “Person” type , we have three properties. GraphExpression.Successors.Count will be equal to numeric value 3 and each of those which are GraphExpression themselves will have only one successor which is a M.Literal. This will actually contain the property name, type and value for parent type ref.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;GraphExpression graphExpression = (GraphExpression) extentDeclaration.InitialValue;

&lt;span class="kwrd"&gt;if&lt;/span&gt; (extentDeclaration.InitialValue != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
{
&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (GraphExpression successor &lt;span class="kwrd"&gt;in&lt;/span&gt; graphExpression.Successors)
{
    &lt;span class="kwrd"&gt;int&lt;/span&gt; index = 0;

    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var expression &lt;span class="kwrd"&gt;in&lt;/span&gt; successor.Successors)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (expression &lt;span class="kwrd"&gt;is&lt;/span&gt; GraphExpression)
        {
            GraphExpression node = (GraphExpression) expression;

            Literal literal = (Literal) (node).Successors[0];
           &lt;span class="rem"&gt;/// process fragment&lt;/span&gt;
        }

        index++;
    }
   &lt;span class="rem"&gt;/// process the final statement&lt;/span&gt;
}&lt;/pre&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;That’s all to get started. All the code has been taken from a MSqlProvider that i created while learning M. The technology is itself in bleeding edge so things will change and i will share my updated knowledge forward. You can further enhance MSQLProvider to run the result in configured database along with the mx.exe that comes with Oslo SDK. &lt;/p&gt;

&lt;p&gt;You can download the source &lt;a href="http://weblogs.asp.net/blogs/mehfuzh/MSQLProvider_3EB0AD29.zip" target="_self"&gt;here&lt;/a&gt; to play around and see it live.&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%2f2009%2f03%2f30%2fprogrammatically-generating-sql-ddl-from-m.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%2f2009%2f03%2f30%2fprogrammatically-generating-sql-ddl-from-m.aspx" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7010618" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=L9xllO5FMM4:4ykgTl5Qb3s:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=L9xllO5FMM4:4ykgTl5Qb3s:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=L9xllO5FMM4:4ykgTl5Qb3s:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=L9xllO5FMM4:4ykgTl5Qb3s:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?i=L9xllO5FMM4:4ykgTl5Qb3s:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/L9xllO5FMM4" height="1" width="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/Oslo/default.aspx">Oslo</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/MGrammer/default.aspx">MGrammer</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2009/03/30/programmatically-generating-sql-ddl-from-m.aspx</feedburner:origLink></item><item><title>Create custom LINQ providers fluently</title><link>http://feedproxy.google.com/~r/burncsharp/~3/ld1Fee61OqU/create-custom-linq-providers-fluently.aspx</link><pubDate>Wed, 25 Feb 2009 15:48:30 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6926008</guid><dc:creator>mehfuzh</dc:creator><slash:comments>4</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6926008</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6926008</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2009/02/25/create-custom-linq-providers-fluently.aspx#comments</comments><description>&lt;p&gt;Just released LinqExtender 2.0. Over previous release , it contains generally bugs fixes. Overall, I have focused on striping out complexity as much as possible to keep you focused on your business logic. You can see the full list of features in the documentation that comes with it.&lt;/p&gt;  &lt;p&gt;Now, while creating the LinqToTwitter example, I have shown that creating custom providers with LinqExtender requires two steps, first you have to define a query object by implementing IQueryObject and then you have made a Query&amp;lt;T&amp;gt; successor and override few methods. In LinqExtender, object/ entity equivalent is Bucket. Starting from 2.0, there is a Fluent interface implementation of it that works as an internal DSL and gives you a single entry point for all query and update , inserts and delete, thus making things more declarative and one way. &lt;/p&gt;  &lt;p&gt;In this post, I will show you how to generate SQL statement from LINQ query with nested &lt;em&gt;where &lt;/em&gt;clause,&lt;em&gt;&amp;#160;&lt;/em&gt;using the fluent interface implementation. To start, let's consider the following query&lt;/p&gt;  &lt;pre class="csharpcode"&gt;var query = from book &lt;span class="kwrd"&gt;in&lt;/span&gt; bookContext
&lt;span class="kwrd"&gt;where&lt;/span&gt; ((book.Author == &lt;span class="str"&gt;&amp;quot;Mehfuz&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp; book.ISBN == &lt;span class="str"&gt;&amp;quot;2&amp;quot;&lt;/span&gt;) || book.Id == books[2].Id) || 
(book.Author == &lt;span class="str"&gt;&amp;quot;Paolo Pialorsi&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp; (book.ISBN == &lt;span class="str"&gt;&amp;quot;100-11-777&amp;quot;&lt;/span&gt; || book.ISBN == &lt;span class="str"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;))
select book;&lt;/pre&gt;

&lt;p&gt;It's taken from the Entrypoint.cs test class that comes with LinqExtender project along with OpenLinqToSql sample ORM. Now, to do things in a very basic way. Let's first create a string builder and append the initial select.&lt;/p&gt;

&lt;p&gt;StringBuilder builder = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder(&lt;span class="str"&gt;&amp;quot;SELECT * FROM [&amp;quot;&lt;/span&gt; + Bucket.Instance.Entity.Name + &lt;span class="str"&gt;&amp;quot;]&amp;quot;&lt;/span&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;To be precise, Bucket.Instance is the entry point for all query and object details. Moving to &lt;em&gt;where statement , &lt;/em&gt;LinqExtender uses simplified expression tree that is exposed by &lt;em&gt;Bucket.Instance.ExpressionTree. A&lt;/em&gt;ll we need to setup how the output will look like and the rest will be covered by the toolkit.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;builder.Append(&lt;span class="str"&gt;&amp;quot;WHERE&amp;quot;&lt;/span&gt;);
builder.Append(&lt;span class="str"&gt;&amp;quot;\r\n&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;Bucket
.Instance
.ExpressionTree
.DescribeContainerAs(builder)
.Root((containter, operatorType) =&amp;gt; containter.Append(&lt;span class="str"&gt;&amp;quot; &amp;quot;&lt;/span&gt; + operatorType + &lt;span class="str"&gt;&amp;quot; &amp;quot;&lt;/span&gt;))
.Begin(container =&amp;gt; container.Append(&lt;span class="str"&gt;&amp;quot;(&amp;quot;&lt;/span&gt;))
.EachLeaf((container, item) =&amp;gt;
 {
     &lt;span class="kwrd"&gt;string&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = GetValue(item.Value);
     container.Append(item.Name + RelationalOperators[item.RelationType] + &lt;span class="kwrd"&gt;value&lt;/span&gt;);
 })
.End(container =&amp;gt; container.Append(&lt;span class="str"&gt;&amp;quot;)&amp;quot;&lt;/span&gt;))
.Execute();&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;Here, let assume that GetValue(..) will return a formatted SQL string and ReleationalOperators is a dictionary that has mappings for item.RealtionType ( GreaterThan -&amp;gt; &amp;quot;&amp;gt;&amp;quot; , LessThan =&amp;gt; &amp;quot;&amp;lt;&amp;quot;, etc). Basically, as the implementation shows, we are defining the way output will be stored in the container (In this case, StringBuilder). All these code should be placed in Query&amp;lt;T&amp;gt;.Process(IModify&amp;lt;T&amp;gt; items) method and on execute it will just return the following SQL block&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Select * from book 
 WHERE
(((Author=&lt;span class="str"&gt;'Mehfuz'&lt;/span&gt; AND ISBN=&lt;span class="str"&gt;'2'&lt;/span&gt;) OR Bk_Id=&lt;span class="str"&gt;'1734'&lt;/span&gt;) 
OR (Author=&lt;span class="str"&gt;'Paolo Pialorsi'&lt;/span&gt; AND (ISBN=&lt;span class="str"&gt;'100-11-777'&lt;/span&gt; OR ISBN=&lt;span class="str"&gt;'1'&lt;/span&gt;))) &lt;/pre&gt;

&lt;p&gt;Extender basically knows how to get though this nested where clause. From basic computer science, it builds linked objects based on a Syntax Tree, with each parenthesis adding diversion to the tree like shown below&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/CreateyourcustomLINQprovidersfluently_FB49/image_2.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/CreateyourcustomLINQprovidersfluently_FB49/image_thumb.png" width="266" height="170" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;So far, this is a very rudimentary example. With 2.0 it is also possible to build your own reusable format provider for building literals that saves repetitive code blocks for same kind of task (updating a database). This is actually just a schema builder that defines how the output will look like using the same Bucket.Instance calls. Out of the box, TSqlFormatProvider is provided.Depending under which Query&amp;lt;T&amp;gt; method it is used; it will generate insert, update, delete or select statement where all you have to call &lt;em&gt;Bucket.Instance.Translate(...)&lt;/em&gt;.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; sql = Bucket.Instance.Translate(&lt;span class="kwrd"&gt;new&lt;/span&gt; TSqlFormatProvider());&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;This enables you to build not only your own LINQ to Anything format providers but also share it with the community to reuse what is already out there. More information on how to get started can be found at the project documentation.&lt;/p&gt;

&lt;p&gt;In a word, Bucket.Instance is all you need to go through and build your own LINQ provider. Optionally, you can override the following methods (under Query&amp;lt;T&amp;gt;) to give your provider various OTS (Object tracking service) support .&lt;/p&gt;

&lt;p&gt;1. AddItem () - called during SubmitChanges() call for new object. 
  &lt;br /&gt;2. RemoveItem () - called during SubmitChanges() call for Delete. 

  &lt;br /&gt;3. UpdateItem () &amp;#8211; called during SubmitChanges() call for update. 

  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;I have updated &lt;a href="http://weblogs.asp.net/mehfuzh/archive/2009/01/01/creating-linqtotwitter-library-using-linqextender.aspx" target="_blank"&gt;Creating LinqToTwitter using LinqExtender&lt;/a&gt; post with the latest release. You can get a copy of the latest 2.0 release from &lt;a href="http://www.codeplex.com/linqextender"&gt;www.codeplex.com/linqextender&lt;/a&gt;,&amp;#160; and of course as usual all your feedbacks are really helping to shape the toolkit.&lt;/p&gt;

&lt;p&gt;Hope that helps,&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff0000"&gt;Update on 28th Feb 2009, with new patch for Bucket.Instance.ExpressionTree&lt;/font&gt;&lt;/p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2009%2f02%2f25%2fcreate-custom-linq-providers-fluently.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%2f2009%2f02%2f25%2fcreate-custom-linq-providers-fluently.aspx" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6926008" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=8UaUjm1o"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=1P8aMPdF"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=52" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=gWGnVMk9"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=XGcfxZqW"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?i=XGcfxZqW" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/ld1Fee61OqU" height="1" width="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><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2009/02/25/create-custom-linq-providers-fluently.aspx</feedburner:origLink></item><item><title>Adding streaming video content to your site</title><link>http://feedproxy.google.com/~r/burncsharp/~3/GhB5Oo4qQe4/adding-streaming-video-content-to-your-site.aspx</link><pubDate>Thu, 29 Jan 2009 15:49:29 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6868377</guid><dc:creator>mehfuzh</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6868377</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6868377</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2009/01/29/adding-streaming-video-content-to-your-site.aspx#comments</comments><description>&lt;p&gt;In my last post, I showed how to turn on Amazon S3 support in Sitefinity. In this post, I will show how to create a simple video site using the video library support that is bundled with 3.6 release. It is often required that you want to add a streaming video content to your site, either it could be a product demonstration or a getting started tutorial. Using third party video provider is one way to get the job done but sometimes it requires a lot of manual work, thus headache for managing them as the library grows bigger. 3.6 release breaks you free from all these and provides an easy way for creating , uploading and managing video content.&lt;/p&gt;  &lt;p&gt;Now, uploading video content and publishing them requires a few easy steps. You can either decide to store / stream it from your hosting server or from Amazon S3, typically which can be divided into following.&lt;/p&gt;  &lt;ol&gt;   &lt;ol&gt;     &lt;li&gt;Configure the data provider &lt;/li&gt;      &lt;li&gt;Create a video library &lt;/li&gt;      &lt;li&gt;Upload videos &lt;/li&gt;      &lt;li&gt;Create a page and add the video content control onto it. &lt;/li&gt;      &lt;li&gt;Publish it. &lt;/li&gt;   &lt;/ol&gt; &lt;/ol&gt;  &lt;p&gt;Sitefinity uses RadMediaPlayer (comes as part of Telerik Rad controls suit), a cool Silverlight media player made on top of the basic MediaPlayer with out of the box features that can get you on the groove right away. As I mentioned already, Sitefinity is a combination of content, modules and pages. Modules can have their own data providers, own handlers, whereas each page can control its content presentation by using the revolutionary control designer.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Addingstreamingvideocontentinyoursite_EE56/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="207" alt="image" src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Addingstreamingvideocontentinyoursite_EE56/image_thumb.png" width="313" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Coming back, to start creating our simple video site first we need to create a module (which is a video library). We can either choose to use the default data provider &amp;quot;Libraries&amp;quot; or we can define our own custom provider. To define one by ourselves we must ensure the following&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Create an entry under &amp;lt;cmsEngine&amp;gt; that looks like &amp;quot;&amp;lt;add name=Libraries...&amp;quot;&amp;#160; or like the one described in Amazon S3 post. &lt;/li&gt;    &lt;li&gt;Add related meta fields under &amp;lt;metaFields&amp;gt; that are same as the default ones with only prefix = &lt;em&gt;name, &lt;/em&gt;you have given to the data provider       &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Libraries.Description&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;valueType&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ShortText&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;visible&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;searchable&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;sortable&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;defaultValue&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;p&gt;&lt;span class="kwrd"&gt;This converters to the following where name = &amp;quot;MyLib&amp;quot;. Similar goes for the rest.&lt;/span&gt;&lt;/p&gt;

    &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;MyLib.Description&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;valueType&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ShortText&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;visible&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;searchable&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;sortable&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;defaultValue&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
  &lt;/li&gt;

  &lt;li&gt;&lt;span class="kwrd"&gt;Map it with &amp;quot;Libraries&amp;quot; module under &lt;em&gt;libraries.genericContentproviders&lt;/em&gt;&lt;/span&gt; 

    &lt;pre class="csharpcode"&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;libraries&lt;/span&gt; &lt;span class="attr"&gt;defaultGenericProvider&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Libraries&amp;quot;&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;genericContentProviders&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;add&lt;/span&gt; &lt;span class="attr"&gt;providerName&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;MyLib&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;publicationDateField&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Publication_Date&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  .........
  .........&lt;/pre&gt;
  &lt;/li&gt;

  &lt;li&gt;Under &lt;em&gt;cmsEngine.providers.add &lt;/em&gt;(where name=&amp;quot;MyLib/Libraries&amp;quot;) there is a key called &lt;em&gt;applicatinName, &lt;/em&gt;which is set to &amp;quot;/Libraries&amp;quot; but we can set it to &amp;quot;/MyOwnApplciation&amp;quot; to ensure that it does not mess data up with the default one. &lt;/li&gt;
&lt;/ul&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;For multiple data providers you will see a &lt;em&gt;dropdown&lt;/em&gt; in the library create wizard, to upload under the specific one, we just need to select and start uploading.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Addingstreamingvideocontentinyoursite_EE56/MultipleLIbrary.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="296" alt="MultipleLIbrary" src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Addingstreamingvideocontentinyoursite_EE56/MultipleLIbrary_thumb.jpg" width="415" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;So, once we have created a video library it will automatically take us to the upload view and once it is done, we can see the preview right away. Next,&amp;#160; we just need to drag and drop the video control onto the page. To further customize it, we can play around with designer that is tied with it (click on the &amp;quot;edit&amp;quot; link) we can set things like the max width for the thumbnail or video player and tweak labels and meta datas as we go.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Addingstreamingvideocontentinyoursite_EE56/VideoEdit_2.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="270" alt="VideoEdit" src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Addingstreamingvideocontentinyoursite_EE56/VideoEdit_thumb_2.jpg" width="427" border="0" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;We have already seen how to set up multiple data providers and select specific libraries from designer. Moreover, we can set custom provider from advance mode of the content control. This applies to all Sitefinity content controls like Events, Blogs, etc that implements the same generic content base class.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Addingstreamingvideocontentinyoursite_EE56/advanced_1.jpg"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="52" alt="advanced" src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Addingstreamingvideocontentinyoursite_EE56/advanced_thumb_1.jpg" width="432" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Finally, if all are set, we will see a video page like the one shown just below. While we are uploading video, each will have a thumbnail generated from the video itself that will be shown in the list view. Each items in list view is tied with a detail view (similar to video sites), where you can play the video, leave comments and bookmark it in your favorite social networking site.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Addingstreamingvideocontentinyoursite_EE56/Video_2.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="338" alt="Video" src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Addingstreamingvideocontentinyoursite_EE56/Video_thumb_2.jpg" width="422" border="0" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;We have already seen in my previous post that we can set the urlRewriteFormat in the data provider declaration. For local libraries , when urlRewriteFormat=&amp;quot;~/{LibraryName}/[Name].sflb.ashx&amp;quot; the video detail permalink will be http://&amp;lt;hostname&amp;gt;/&amp;lt;applicationPath&amp;gt;/&amp;lt;pagename&amp;gt;/MyLib/ButterFly.aspx, that means the video content control (detail view) will have the same mirror URL terminating with &amp;quot;*.aspx&amp;quot;. So, if you change the URL format in library data provider it will reflect in the content control as well.&lt;/p&gt;

&lt;p&gt;So far, that's all for the simple video site. Let us know, how you like to shape it for you and what features you really want to add in it. You can grab a free &lt;a href="http://www.sitefinity.com/product/community-edition.aspx" target="_blank"&gt;community edition&lt;/a&gt;&amp;#160; and of course any feedback will really make us feel better.&lt;/p&gt;

&lt;p&gt;Hope that helps&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2009%2f01%2f29%2fadding-streaming-video-content-to-your-site.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%2f2009%2f01%2f29%2fadding-streaming-video-content-to-your-site.aspx" border="0" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6868377" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=vkr4R2D3"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=s10cR0EJ"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=52" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=BUNEo9pB"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=tCZMT6g9"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?i=tCZMT6g9" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/GhB5Oo4qQe4" height="1" width="1"/&gt;</description><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/Sitefiinity/default.aspx">Sitefiinity</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2009/01/29/adding-streaming-video-content-to-your-site.aspx</feedburner:origLink></item><item><title>Amazon S3 support in Sitefinity 3.6</title><link>http://feedproxy.google.com/~r/burncsharp/~3/-w3wxv4mT-0/amazon-s3-support-in-sitefinity-3-6.aspx</link><pubDate>Fri, 23 Jan 2009 08:27:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6858172</guid><dc:creator>mehfuzh</dc:creator><slash:comments>16</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6858172</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6858172</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2009/01/23/amazon-s3-support-in-sitefinity-3-6.aspx#comments</comments><description>&lt;P&gt;Here at Telerik, Sitefinity team is preparing for the 3.6 release next week. 3.6 comes with lot of core level enhancements and cool new features. Of which , I can't but mention one feature that will make most ISV vendors who want the power of CMS but want to let go their pain of managing large content. As, the title suggests its external storage support via Amazon S3. The data plan for hosting and transferring data to/from S3 server is pretty cheap these days in return to world class service with almost zero downtime that it offers which of course makes the most of your money. If you are not familiar with Sitefinity to add it is a product by &lt;A href="http://www.telerik.com/" target=_blank mce_href="http://www.telerik.com"&gt;Telerik&lt;/A&gt;&amp;nbsp; that comes with full content management features along with blogs, news, events, list and few other pre-made modules with easy setup and management via unique control designer.&lt;/P&gt;
&lt;P&gt;In this post, I will show how to turn on S3 support in Sitefinity 3.6 that comes out of the box.In Sitefinity, files are kept in Library. Every file which can be audio, video, document or anything else is stored as Library entries, which are consumed by modules for example images in blog post. These library entries are dependant on data providers which can be extended from internal to cloud. S3 support is just a plugin to that extensibility.&lt;/P&gt;
&lt;P&gt;Now, to configure S3 support let's start with a simple example. I want to create a personal blog and I want all the images and attachments go to Amazon S3 server. To do so , we need to ensure the following&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Turn on the S3 data provider in web.config (that comes with the installation) &lt;/LI&gt;
&lt;LI&gt;Add your S3 API and secret key to the specific place holder. &lt;/LI&gt;
&lt;LI&gt;Create your blog module &lt;/LI&gt;
&lt;LI&gt;Drag and drop your module over a page. &lt;/LI&gt;
&lt;LI&gt;Publish it &lt;/LI&gt;
&lt;LI&gt;Use Admin or Live writer to do your post with Images and attachments. &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Steps 3- 6 are pretty basic and are beyond the scope of this post. I will deeply encourage you to grab a community version from the project's download page(link provided at the end) and see the step by step documentation that comes right with it.&lt;/P&gt;
&lt;P&gt;To start setting up, first we need to navigate to the &lt;EM&gt;&lt;STRONG&gt;cmsEngine&lt;/STRONG&gt;&lt;/EM&gt; node. If amazon block is there then un-comment it and remove the default "Libraries" data provider or less add the following data provider.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;add&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Libraries"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;urlRewriteFormat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="~/{LibraryName}/[Name].s3lb"&lt;/SPAN&gt; 
    &lt;SPAN class=attr&gt;thumbnailExtension&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;=".tmb"&lt;/SPAN&gt;
    &lt;SPAN class=attr&gt;urlDateTimeFormat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="yy-MM-dd"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;urlWhitespaceChar&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="_"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;visible&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="False"&lt;/SPAN&gt; 
&lt;SPAN class=attr&gt;    defaultMetaField&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Name"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;applicationName&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="/Libraries"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;allowVersioning&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="True"&lt;/SPAN&gt; 
&lt;SPAN class=attr&gt;    allowLocalization&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="False"&lt;/SPAN&gt;
&lt;SPAN class=attr&gt;    localizationProviderName&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;=""&lt;/SPAN&gt; &lt;SPAN class=attr&gt;allowWorkflow&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="False"&lt;/SPAN&gt; 
&lt;SPAN class=attr&gt;    securityProviderName&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;=""&lt;/SPAN&gt; &lt;SPAN class=attr&gt;versioningProviderName&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;=""&lt;/SPAN&gt;
    &lt;SPAN class=attr&gt;connectionStringName&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="GenericContentConnection"&lt;/SPAN&gt; 
&lt;SPAN class=attr&gt;    type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Telerik.Libraries.Data.AmazonProvider, Telerik.Libraries.Data"&lt;/SPAN&gt;
&lt;SPAN class=attr&gt;    tagEditorTemplate&lt;/SPAN&gt;=&lt;SPAN class=kwrd&gt;"~/Sitefinity/Admin/ControlTemplates/Libraries/BatchTagsEditor.ascx"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	FONT-SIZE: small; COLOR: black; FONT-FAMILY: consolas, "Courier New", courier, monospace; BACKGROUND-COLOR: #ffffff
}
.csharpcode PRE {
	FONT-SIZE: small; COLOR: black; FONT-FAMILY: consolas, "Courier New", courier, monospace; BACKGROUND-COLOR: #ffffff
}
.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 {
	MARGIN: 0em; WIDTH: 100%; BACKGROUND-COLOR: #f4f4f4
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;Now, inside the data provider you can do plenty of tweaks like, modify the URL format , turn on/off localization, have multiple providers of same type (with different &lt;EM&gt;name&lt;/EM&gt;) and map it from admin, etc. The most important thing for libraries or any other module is the urlRewriteFormat. You can set up any format and the detail (permalink) url will generate accordingly. Here, [Name] = name of the file but you can change it to any meta fields that the module supports or add any constants you want.&lt;/P&gt;
&lt;P&gt;The amazon data provider is different in two ways from local one &lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;It has different content extension(.s3lb). &lt;/LI&gt;
&lt;LI&gt;Separate data provider dedicated to communicate with S3. Default type = Telerik.Libraries.Data.DefaultProvider &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;As, we are pretty much done with the first step. Next, we have to put the right API and secret access key that we have purchased from Amazon. All the transfers will be made against the key associated to a user's account. Under the &lt;EM&gt;&lt;STRONG&gt;telerik&lt;/STRONG&gt;&lt;/EM&gt; node we have a section called &lt;EM&gt;&lt;STRONG&gt;storageSetting&lt;/STRONG&gt;&lt;/EM&gt; which looks like&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;storageSetting&lt;/SPAN&gt; &lt;SPAN class=attr&gt;defaultProvider&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Amazon"&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;providers&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;add&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Amazon"&lt;/SPAN&gt;           
          &lt;SPAN class=attr&gt;type&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Telerik.Libraries.AmazonStorage.AmazonStorageProvider, Telerik.Libraries"&lt;/SPAN&gt; 
          &lt;SPAN class=attr&gt;downloadUrlPrefix&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://s3.amazonaws.com"&lt;/SPAN&gt; 
          &lt;SPAN class=attr&gt;accessKey&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="YOUR ACCESS KEY"&lt;/SPAN&gt;
          &lt;SPAN class=attr&gt;secretAccessKey&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="YOUR SECRECT KEY"&lt;/SPAN&gt;
          &lt;SPAN class=attr&gt;bucketName&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Sitefinity"&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;providers&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;storageSetting&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Just Fill in the gaps and you are through. In Sitefinity module is the heart of every content and a page can contain 1..N modules but each module can have its own specific settings like data provider, URL format, etc. As we have finished setting up the data provider and associated configuration to talk with S3 server. we can now play the way we like. We can create gallery with image library or setup&amp;nbsp; a download list for providing documents and pdfs. Even we can setup a video site(which I will cover in later post) easily. But for now , let's create a blog, write a post, add some images and text and publish it.&lt;/P&gt;
&lt;P&gt;&lt;A class="" href="http://weblogs.asp.net/blogs/mehfuzh/myGif.gif" mce_href="http://weblogs.asp.net/blogs/mehfuzh/myGif.gif"&gt;&lt;/A&gt;&lt;IMG title="SiteFinity Admin page edit" style="WIDTH: 500px; HEIGHT: 283px" height=283 alt="SiteFinity Admin page edit" src="http://weblogs.asp.net/blogs/mehfuzh/myGif.gif" width=500 mce_src="http://weblogs.asp.net/blogs/mehfuzh/myGif.gif"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above is the snap of edit mode of the blog page along with the post that I have done using Live Writer. Now, to be more sure (we haven't done any wrong) if you monitor using firebug Net tab your list will look like the pasted&lt;/P&gt;
&lt;P&gt;&lt;A class="" href="http://weblogs.asp.net/blogs/mehfuzh/FirebugAmazonSite.JPG" mce_href="http://weblogs.asp.net/blogs/mehfuzh/FirebugAmazonSite.JPG"&gt;&lt;/A&gt;&lt;IMG title="Fiirbug stat" style="WIDTH: 555px; HEIGHT: 180px" height=180 alt="Fiirbug stat" src="http://weblogs.asp.net/blogs/mehfuzh/FirebugAmazonSite.JPG" width=555 mce_src="http://weblogs.asp.net/blogs/mehfuzh/FirebugAmazonSite.JPG"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Down in the bottom there are two request for images posted by Live Writer which are directly forwarded to S3 server (302-&amp;gt;200). Thus, the whole load goes to Amazon and gives you peaceful night sleep.&lt;/P&gt;
&lt;P&gt;This is basically shortly all for now, I will cover more things from Sitefinity like creating video site , working with Sitefinity designers to configure your site without touching any of the html code and more that is interesting in my future posts.&lt;/P&gt;
&lt;P&gt;Till then, you can get a free copy from &lt;A class="" title=http://www.sitefinity.com/product/community-edition.aspx href="http://www.sitefinity.com/product/community-edition.aspx" target=_blank mce_href="http://www.sitefinity.com/product/community-edition.aspx"&gt;http://www.sitefinity.com/product/community-edition.aspx&lt;/A&gt; (you need to create an account if you haven't. You can use it for other Telerik products and to log any issues as well.&lt;/P&gt;
&lt;P&gt;Hope that helps&lt;/P&gt;&lt;A href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2009%2f01%2f23%2famazon-s3-support-in-sitefinity-3-6.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%2f2009%2f01%2f23%2famazon-s3-support-in-sitefinity-3-6.aspx" border=0&gt;&lt;/A&gt; &lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6858172" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=ULa6fAsa"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=r0rMM80h"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=52" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=OCjTmack"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=MRziXCus"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?i=MRziXCus" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/-w3wxv4mT-0" height="1" width="1"/&gt;</description><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/Sitefiinity/default.aspx">Sitefiinity</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2009/01/23/amazon-s3-support-in-sitefinity-3-6.aspx</feedburner:origLink></item><item><title>Creating LINQToTwitter library using LinqExtender</title><link>http://feedproxy.google.com/~r/burncsharp/~3/u-3xEMnXt34/creating-linqtotwitter-library-using-linqextender.aspx</link><pubDate>Thu, 01 Jan 2009 17:53:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6811649</guid><dc:creator>mehfuzh</dc:creator><slash:comments>15</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6811649</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6811649</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2009/01/01/creating-linqtotwitter-library-using-linqextender.aspx#comments</comments><description>&lt;p&gt;In this post, I will show how to cook an LINQToTwitter library with LinqExtender. My target is to create it easily and over existing twitter API. I used &lt;a href="http://devblog.yedda.com" target="_blank"&gt;Yedda&lt;/a&gt; Twitter library. Yedda library basically returns response in XML/JSON/RSS/ATOM format depending on the option provided. I used XML format and serialized it to objects. &lt;/p&gt;  &lt;p&gt;Now, with our LINQToTwitter we will be able to get public/user/friend's timeline, sort them via date, screen name. Finally, we will be able to update our status. Twitter response format for status looks like&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;statuses&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;status&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;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;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;status&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;statuses&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;For this, I have created a class named &lt;/span&gt;&lt;span class="kwrd"&gt;&lt;u&gt;Twit&lt;/u&gt; that maps to the status and a class name &lt;u&gt;User&lt;/u&gt; that is used as an auto property in &lt;u&gt;Twit&lt;/u&gt;. These two classes contain some Xml Serialization attributes&amp;#160; by which response is serialized to respective properties.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;We have our Twitter API in place, the next step is to make them LINQ-able. Prior to the latest release to make an object queryable, it is required to inherit from QueryObjectBase. Using this approach the feed back I got from users that they need to try LINQ in their existing data objects, which is already inherited from a base class and they need to change a lot for using the abstract approach. The new release just solves that with a blank IQueryObject interface, which makes it more easier to port LINQ into existing data object in no time.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;Building LINQ providers with LinqExtender requires few easy steps. &lt;/span&gt;&lt;span class="kwrd"&gt;First, Create or convert an object to be queryable by implementing IQueryObject interface. With our Twit object it looks like&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/CreatingaLINQToTwitterusingLinqExtender_130AE/image_10.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/CreatingaLINQToTwitterusingLinqExtender_130AE/image_thumb_4.png" width="464" height="169" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Here, note that I added &lt;em&gt;UniqueIdentifier&lt;/em&gt; attribute on top of &lt;em&gt;Id&lt;/em&gt; property that makes the object trackable during add, update or delete. Every object should have property that distinguishes entities from each other and should be marked Unique. There is another attribute called &lt;em&gt;Ignore&lt;/em&gt;. If we want properties not to be processed by the toolkit we can just put the attribute on top. Once, it is done next we have to create query provider that will be used for making LINQ queries. Let's name it &lt;u&gt;TwitterContext&lt;/u&gt; and it needs to inherit Query&amp;lt;Twit&amp;gt; and override few methods depending on support that the library is going to provide.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/CreatingaLINQToTwitterusingLinqExtender_130AE/image_3.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/CreatingaLINQToTwitterusingLinqExtender_130AE/image_thumb.png" width="458" height="85" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now, as I said earlier that we will be doing some queries by timeline and update our status. While adding new items we need to override Query&amp;lt;Twit&amp;gt;.AddItem where we will add object to repository and update any property that we need to get and finally return true/ false depending on the execution status.&lt;/p&gt;

&lt;p&gt;Inside Query&amp;lt;Twit&amp;gt;.AddItem it looks like (Partially).&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; username = (&lt;span class="kwrd"&gt;string&lt;/span&gt;)Bucket.Instance.For.Item(QueryItems.USERNAME).Value;
&lt;span class="kwrd"&gt;string&lt;/span&gt; password = (&lt;span class="kwrd"&gt;string&lt;/span&gt;)Bucket.Instance.For.Item(QueryItems.PASSWORD).Value;

Validate(username, password);

&lt;span class="kwrd"&gt;string&lt;/span&gt; statusText = (&lt;span class="kwrd"&gt;string&lt;/span&gt;)Bucket.Instance.For.Item(&lt;span class="str"&gt;&amp;quot;Text&amp;quot;&lt;/span&gt;).Value;
&lt;span class="kwrd"&gt;string&lt;/span&gt; source = (&lt;span class="kwrd"&gt;string&lt;/span&gt;)Bucket.Instance.For.Item(&lt;span class="str"&gt;&amp;quot;Source&amp;quot;&lt;/span&gt;).Value;

Twitter twitter = &lt;span class="kwrd"&gt;new&lt;/span&gt; Twitter();

&lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(source))
{
    twitter.Source = source;
}

&lt;span class="kwrd"&gt;string&lt;/span&gt; response = twitter.Update(username, password, statusText, Twitter.OutputFormatType.XML);

Twit twit = XmlToObject&amp;lt;Twit&amp;gt;.Deserialize(response);
Type twitType = twit.GetType();

Bucket.Instance.For.EachItem
.Process(&lt;span class="kwrd"&gt;delegate&lt;/span&gt;(BucketItem item)
 {
     item.Value = twitType.GetProperty(item.Name).GetValue(twit, &lt;span class="kwrd"&gt;null&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;The code is pretty simple as we can see that we are getting the required values from bucket object , setting them into Twitter API, updating the result object (Twit) and finally returning TRUE that will tell LinqExtender to update it's collection. For any FALSE or exception toolkit will remove the partial object. There are other methods that we can override like UpdateItem, RemoveItem, GetItem. Due to the API constraint we will skip them now. But you can check them out at the project documentation or in the provided OpenLinqToSql ORM.&lt;/p&gt;

&lt;p&gt;Next, we need to override the Query&amp;lt;Twit&amp;gt;.Process which will be handling the LINQ queries we make. &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;Twit&amp;gt; items)
{
    &lt;span class="kwrd"&gt;string&lt;/span&gt; response = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty;

    Twitter twitter = &lt;span class="kwrd"&gt;new&lt;/span&gt; Twitter();

    &lt;span class="rem"&gt;/// general select statement with no where clause.&lt;/span&gt;
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (!Bucket.Instance.IsDirty)
    {
        response = twitter.GetPublicTimeline(Twitter.OutputFormatType.XML);
    }
    &lt;span class="kwrd"&gt;else&lt;/span&gt;
    {
            &lt;span class="kwrd"&gt;string&lt;/span&gt; username = (&lt;span class="kwrd"&gt;string&lt;/span&gt;)Bucket.Instance.For.Item(QueryItems.USERNAME).Value;
            &lt;span class="kwrd"&gt;string&lt;/span&gt; password = (&lt;span class="kwrd"&gt;string&lt;/span&gt;)Bucket.Instance.For.Item(QueryItems.PASSWORD).Value;
            &lt;span class="kwrd"&gt;object&lt;/span&gt; obj = (Timeline)Bucket.Instance.For.Item(QueryItems.TIMELINE).Value;

            &lt;span class="kwrd"&gt;if&lt;/span&gt; (obj == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Exception(&lt;span class="str"&gt;&amp;quot;Must provide a valid timeline&amp;quot;&lt;/span&gt;);
            }

            Timeline timeline = (Timeline) obj;

            &lt;span class="kwrd"&gt;if&lt;/span&gt; (timeline == Timeline.Friends)
            {
                Validate(username, password);
                response = twitter.GetFriendsTimeline(username, password, Twitter.OutputFormatType.XML);
            }
            &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (timeline == Timeline.User)
            {
                response = twitter.GetUserTimeline(username, password, Twitter.OutputFormatType.XML);
            }
        }

        Twits twits = XmlToObject&amp;lt;Twits&amp;gt;.Deserialize(response);

        &lt;span class="rem"&gt;/// do some extra in-memory stuff which are not supported by API&lt;/span&gt;
        IList&amp;lt;Twit&amp;gt; list = GetList(twits);

        items.AddRange(list, &lt;span class="kwrd"&gt;true&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;Here, we can see that &lt;em&gt;Bucket.Instance.IsDirty&lt;/em&gt; is used for public timelines. When &lt;em&gt;Bucket.Instance.IsDirty = false&lt;/em&gt;, we can be sure that no where clause is used and as such we can decide to handle the way we want. IModify&amp;lt;T&amp;gt;.AddRange with true tells the toolkit to do in-memory sort when orderby is used. There is another way to do sort (natural sort) by which we can pass in the sort data to source (if supported) and in that case we can either pass false or use the other overload of AddRange or even add items one by one.&lt;/p&gt;

&lt;p&gt;This is our simple LINQToTwitter library so far. To start let's do some queries. First, I want to get my friend's timeline sorted by last updated date.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;TwitterContext context = new TwitterConext();&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;var query = from twit &lt;span class="kwrd"&gt;in&lt;/span&gt; context
             &lt;span class="kwrd"&gt;where&lt;/span&gt; twit.Username == &lt;span class="str"&gt;&amp;quot;myuser&amp;quot;&lt;/span&gt;
                       &amp;amp;&amp;amp; twit.Password == &lt;span class="str"&gt;&amp;quot;mypass&amp;quot;&lt;/span&gt;
                       &amp;amp;&amp;amp; twit.Timeline == Timeline.Friends
             orderby twit.LastUpdated descending
             select twit;

&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var t &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;p&gt;I also want to update my status. To do so, the following needs to be done.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Twit twitObject = &lt;span class="kwrd"&gt;new&lt;/span&gt; Twit()
{
  Username = USERNAME,
  Password = PASSWORD,
  Text = &lt;span class="str"&gt;&amp;quot;Happy new year to all&amp;quot;&lt;/span&gt;
};
context.Add(twitObject);
context.SubmitChanges();

&lt;span class="kwrd"&gt;if&lt;/span&gt; (!&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(twitObject.Id))
{
    /&lt;span class="rem"&gt;// do something&lt;/span&gt;
}&lt;/pre&gt;

&lt;p&gt;There are few other queries that can be made. You can download the &lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/CreatingaLINQToTwitterusingLinqExtender_130AE/LinqToTwitter_1.zip" target="_self"&gt;source here&lt;/a&gt;. I have shown here very few of the options in LinqExtender, to know more check out the word document at &lt;a href="http://www.codeplex.com/LinqExtender/Release/ProjectReleases.aspx?ReleaseId=23620" target="_blank"&gt;project's release page&lt;/a&gt;. Also, check the OpenLinqToSql ORM that is made on it and comes out of the box. &lt;/p&gt;

&lt;p&gt;Enjoy!!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff0000"&gt;Updated on Feb 24th 2009 with LinqExtender 2.0&lt;/font&gt;&lt;/strong&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;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2009%2f01%2f01%2fcreating-linqtotwitter-library-using-linqextender.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%2f2009%2f01%2f01%2fcreating-linqtotwitter-library-using-linqextender.aspx" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6811649" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=WquUs9TG"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=YhVyeOFY"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=52" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=HKOvWT05"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=rEtpXhn5"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?i=rEtpXhn5" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/u-3xEMnXt34" height="1" width="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/LinqExtender/default.aspx">LinqExtender</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LinqToTwitter/default.aspx">LinqToTwitter</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2009/01/01/creating-linqtotwitter-library-using-linqextender.aspx</feedburner:origLink></item><item><title>Making cross domain web requests in asp.net with medium trust enabled</title><link>http://feedproxy.google.com/~r/burncsharp/~3/OFUafy-Sslw/making-cross-domain-web-requests-in-asp-net-with-medium-trust-enabled.aspx</link><pubDate>Sun, 07 Dec 2008 17:45:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6769729</guid><dc:creator>mehfuzh</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6769729</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6769729</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/12/07/making-cross-domain-web-requests-in-asp-net-with-medium-trust-enabled.aspx#comments</comments><description>&lt;P&gt;There could be plenty of reason that you might need to do a cross domain web request in your application. One could be let's say you want to divert the resource pressure from your server to some third party content&amp;nbsp;provider like Amazon S3. In my last post I have mentioned a bit about uploading content using WSE to S3 server. I also mentioned about the simple library located at &lt;A href="http://www.codeplex.com/threesharp" target=_blank&gt;www.codeplex.com/threesharp&lt;/A&gt; that does not necessarily require you to work in full trust mode.&amp;nbsp;This is also true if&amp;nbsp;you have a personalized startpage where you want your wideget developers to restrict&amp;nbsp;to partiuclar URLs. &lt;/P&gt;
&lt;P&gt;Now, before starting it is worth mentioning that in medium trust mode any cross domain&amp;nbsp;request is disabled by default. In other words, you can do calls only for your local endpoints. &lt;/P&gt;
&lt;P&gt;How to get around this ?&lt;/P&gt;
&lt;P&gt;When you install .net framework under &lt;STRONG&gt;%installed dir%\framework\version\config&lt;/STRONG&gt; you will find a web_(high or medium or low)trust.config file that defines some policy about how your application will behave in a particular security level specified.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Makingcrossdom.netwithmediumtrustenabled_11F29/trustLevel_2.jpg" mce_href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Makingcrossdom.netwithmediumtrustenabled_11F29/trustLevel_2.jpg"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=146 alt=trustLevel src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Makingcrossdom.netwithmediumtrustenabled_11F29/trustLevel_thumb.jpg" width=334 border=0 mce_src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Makingcrossdom.netwithmediumtrustenabled_11F29/trustLevel_thumb.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Now, to customize the default medium trust settings best is to copy it to your application directory so that you can tweaks thing only for your application and don't end up making it unstable in global scope. To show it as an example I have created a sample project that tries to do a web request, gets the data out and finally stuffs it to the response stream. To simulate, first let's put the following line in web.config which is pretty general for those of you works with it daily to strictly support medium trust in your app.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;trust&lt;/SPAN&gt; &lt;SPAN class=attr&gt;level&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Medium"&lt;/SPAN&gt;  &lt;SPAN class=kwrd&gt;/&amp;gt; // this is only for simulating in localhost&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Next is to define your security level and config that will look for policies&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;securityPolicy&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;trustLevel&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Medium"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;policyFile&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="web_mediumtrust.config"&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;securityPolicy&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;The above line&amp;nbsp;will come into action only&amp;nbsp;when medium trust is enabled. But here to&amp;nbsp;note that&amp;nbsp;if you dont have control over your hosting provider or your&amp;nbsp;hosting has a &lt;STRONG&gt;&amp;lt;location allowOverride="false"&amp;gt;&lt;/STRONG&gt; node in the root config then this approach&amp;nbsp;won't work. Either you have to tell your hosting provider to add the requested URL for you or if you are doing things&amp;nbsp;with your own hosting then you have to do it by yourself :-).&lt;/P&gt;
&lt;P&gt;If you generally try to do a web request without any predefined policy defined in medium trust then you might see the following error&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;To overcome, once you have medium trust config in place you need to override the connectAccess property of &lt;EM&gt;WebPermission&lt;/EM&gt; class. To do so , let's say I want to grant request for search.&lt;EM&gt;live.com &lt;/EM&gt;and its descendant URLs, so the changes that I need to make looks something like the pasted.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;IPermission&lt;/SPAN&gt; &lt;SPAN class=attr&gt;class&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="WebPermission"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;version&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;ConnectAccess&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;URI&lt;/SPAN&gt; &lt;SPAN class=attr&gt;uri&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://www\.live\.com/.*"&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;ConnectAccess&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;IPermission&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;The default URL for requests in medium trust config is set to &lt;EM&gt;$OriginHost$&lt;/EM&gt; which says, "Can't let you do request to domains other than your own :-)" . The URL property takes regular expression and I can grant as many as URLs I want just by adding a new URL element and associating it with proper endpoint that my API or application might call.&amp;nbsp; You can download the sample &lt;A href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Makingcrossdom.netwithmediumtrustenabled_11F29/MediumTrustDemo_1.zip" target=_blank mce_href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Makingcrossdom.netwithmediumtrustenabled_11F29/MediumTrustDemo_1.zip"&gt;here&lt;/A&gt; and hope that helps a bit.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Update : As most of the shared hosting are with &amp;lt;location allowOverride="false"&amp;gt; the approach is useful only if you are a system administrator or want to&amp;nbsp;have full control over your site by restricting your widget developers to a limited URLs&lt;/STRONG&gt;&lt;/EM&gt;&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%2f12%2f07%2fmaking-cross-domain-web-requests-in-asp-net-with-medium-trust-enabled.aspx"&gt;&lt;IMG alt="kick it on &amp;#13;&amp;#10;DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f12%2f07%2fmaking-cross-domain-web-requests-in-asp-net-with-medium-trust-enabled.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=6769729" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=RPIWvtTr"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=Y7hNtIpy"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=52" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=NniorEMR"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=KsR390ki"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?i=KsR390ki" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/OFUafy-Sslw" height="1" width="1"/&gt;</description><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/General/default.aspx">General</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Server/default.aspx">Server</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/System+Administration/default.aspx">System Administration</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2008/12/07/making-cross-domain-web-requests-in-asp-net-with-medium-trust-enabled.aspx</feedburner:origLink></item><item><title>Working out with Amazon S3</title><link>http://feedproxy.google.com/~r/burncsharp/~3/7ObRs8Xm2M4/working-out-with-amazon-s3.aspx</link><pubDate>Sun, 30 Nov 2008 17:08:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6760864</guid><dc:creator>mehfuzh</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6760864</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6760864</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/11/30/working-out-with-amazon-s3.aspx#comments</comments><description>&lt;P&gt;Recently, I was bit playing around with amazon S3. This is said to be the cheapest storage for people who don't want to spend much of their brain cells thinking about DB issues. Now, Amazon S3 primarily supports Web service (SOAP) to store and query data out of the S3 server. The concept behind S3 is that you have to create a bucket and under it you can store as many objects you want. Generally for a particular account 100 is the threshold value for buckets. In this post, I will basically focus on configuring your proxy for uploading large files to amazon using WSE and optionally I will point out a cool browser extension for analyzing your S3 space and third party library alternative.&lt;/P&gt;
&lt;P&gt;Amazon depends on WSE 2.0 if you want to upload files larger than 1MB. The large file is transferred in the form of DIME (Direct Internet Message Encapsulation) attachment. Microsoft has released WSE 3.0 that uses MTOM which is a W3C recommendation for replacing DIME. But the time of writing this post it is not yet supported by Amazon.&lt;/P&gt;
&lt;P&gt;How to prepare your proxy to support DIME&amp;nbsp; ?&amp;nbsp; Well, first you have to get the WSE 2.0 SP3 from Microsoft downloads. Once the step is completed, you can copy the Microsoft.Web.Services2.dll to your local folder. Basically, once the WSE 2.0 pack is installed the DLL is added to the GAC so it is not a required step, but if you want to ship it along with your distribution then you can consider doing that.&lt;/P&gt;
&lt;P&gt;Now once you have created the proxy from &lt;EM&gt;http://s3.amazonaws.com/doc/2006-03-01/AmazonS3.wsdl.&lt;/EM&gt; You need to do some manual tweaks before your project is ready to go with WSE. &lt;/P&gt;
&lt;P&gt;From the Diff for &lt;EM&gt;Reference.cs&lt;/EM&gt; we can see that we have to add a reference to Microsoft.Web.Services2 and inherit from WebServicesClientProtocol instead of SoapHttpClientProtocol&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/WorkingoutwithAmazonS3_13398/ReferenceDiff_1.jpg" mce_href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/WorkingoutwithAmazonS3_13398/ReferenceDiff_1.jpg"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=274 alt=ReferenceDiff src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/WorkingoutwithAmazonS3_13398/ReferenceDiff_thumb_1.jpg" width=521 border=0 mce_src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/WorkingoutwithAmazonS3_13398/ReferenceDiff_thumb_1.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Pretty easy but hang on a bit. While you are instantiating the proxy class you have to add/remove some standard WS filters. Therefore, if we have a method called CreateProxyInstance , with the OutputFilters it will look like&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; AmazonS3 CreateProxyInstance()
{
    AmazonS3 proxy = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; AmazonS3();

    &lt;SPAN class=rem&gt;/// Remove the standard WSE soap headers.&lt;/SPAN&gt;
    proxy.Pipeline.OutputFilters.Remove(&lt;SPAN class=kwrd&gt;typeof&lt;/SPAN&gt;(Microsoft.Web.Services2.Security.SecurityOutputFilter));
    proxy.Pipeline.OutputFilters.Remove(&lt;SPAN class=kwrd&gt;typeof&lt;/SPAN&gt;(Microsoft.Web.Services2.Referral.ReferralOutputFilter));
    proxy.Pipeline.OutputFilters.Remove(&lt;SPAN class=kwrd&gt;typeof&lt;/SPAN&gt;(Microsoft.Web.Services2.Policy.PolicyEnforcementOutputFilter));

    &lt;SPAN class=rem&gt;/// Add our custom filter to remove the unwanted WSE soap headers.&lt;/SPAN&gt;
    proxy.Pipeline.OutputFilters.Add(&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; HeaderOutputFilter(&lt;SPAN class=str&gt;"wsa:"&lt;/SPAN&gt;));

    &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; proxy;
}&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;Here the HeaderOuputFilter is a inherited from SoapOutputFilter , where we build the SoapEnvolop header without &lt;EM&gt;wsa &lt;/EM&gt;node. Pretty much that's it for setting up the proxy , now let's upload something to the S3 server.&lt;/P&gt;&lt;PRE class=csharpcode&gt;MetadataEntry[] metadataEntries = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; MetadataEntry[2];

metadataEntries[0] = mContentType;
metadataEntries[1] = contentLength;

DateTime timestamp = GetCurrentTimeInMilliseconds();
&lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; signature = GenerateSignature(&lt;SPAN class=str&gt;"PutObject"&lt;/SPAN&gt;, timestamp);

&lt;SPAN class=kwrd&gt;using &lt;/SPAN&gt;(AmazonS3 proxy = CreateProxyInstance())
{
    MemoryStream stream = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; MemoryStream(content);
    Microsoft.Web.Services2.Dime.DimeAttachment dimeAttachment = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; 
    Microsoft.Web.Services2.Dime.DimeAttachment(&lt;SPAN class=str&gt;"S3Object"&lt;/SPAN&gt;,   
    Microsoft.Web.Services2.Dime.TypeFormat.Unknown, stream);
    dimeAttachment.ContentType = contentType; &lt;/PRE&gt;&lt;PRE class=csharpcode&gt;    &lt;SPAN class=rem&gt;/// add the object in wire.&lt;/SPAN&gt;
    proxy.RequestSoapContext.Attachments.Add(dimeAttachment);
    proxy.PutObject(_bucketName, key, metadataEntries, content.LongLength, grants, 
    StorageClass.STANDARD, &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;, _accessKey, timestamp, &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;, signature, &lt;SPAN class=kwrd&gt;null&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;From the fragmented code block we can see that "PutObject" is the method for large content not "PutObjectInLine" and along passing the stream, we have to pass the content type as well or less it wont recognized properly even you specify it in the MimeDataEntry array. &lt;/P&gt;
&lt;P&gt;So far that is all. I have joined in a tiny class library project that will be helpful if you are getting started with S3 using SOAP. You can download it &lt;A href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/WorkingoutwithAmazonS3_13398/AmazonStorage_1.zip" target=_self mce_href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/WorkingoutwithAmazonS3_13398/AmazonStorage_1.zip"&gt;HERE.&lt;/A&gt; About the tool there is a cool firefox addon called &lt;STRONG&gt;S3Fox&lt;/STRONG&gt; that gives you an explorer look for analyzing and even let you to add/delete items directly from S3.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/WorkingoutwithAmazonS3_13398/s3Fox_2.jpg" mce_href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/WorkingoutwithAmazonS3_13398/s3Fox_2.jpg"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=217 alt=s3Fox src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/WorkingoutwithAmazonS3_13398/s3Fox_thumb.jpg" width=381 border=0 mce_src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/WorkingoutwithAmazonS3_13398/s3Fox_thumb.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Finally, WSE 2.0 does not work in medium trust mode which is an absolute show stopper for CMS and blog solutions. There is a nice S3 library at codeplex can be found at &lt;A href="http://www.codeplex.com/ThreeSharp" target=_blank mce_href="http://www.codeplex.com/ThreeSharp"&gt;www.codeplex.com/ThreeSharp&lt;/A&gt; that don't requires any of these and can be a good alternative for medium trust problem.&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%2f11%2f30%2fworking-out-with-amazon-s3.aspx" mce_href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f11%2f30%2fworking-out-with-amazon-s3.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%2f11%2f30%2fworking-out-with-amazon-s3.aspx" border=0 mce_src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f11%2f30%2fworking-out-with-amazon-s3.aspx"&gt;&lt;/A&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6760864" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=UsuDCUyj"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=jY9ITS5H"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=52" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=8NPnA5vr"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=G5viCp8x"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?i=G5viCp8x" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/7ObRs8Xm2M4" height="1" width="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/S3/default.aspx">S3</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Amazon/default.aspx">Amazon</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2008/11/30/working-out-with-amazon-s3.aspx</feedburner:origLink></item><item><title>Retrospective of PDC 2008 [From my view]</title><link>http://feedproxy.google.com/~r/burncsharp/~3/3MqCYFC7wLU/retrospective-of-pdc-2008-from-my-view.aspx</link><pubDate>Sun, 09 Nov 2008 07:34:22 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6727131</guid><dc:creator>mehfuzh</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6727131</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6727131</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/11/09/retrospective-of-pdc-2008-from-my-view.aspx#comments</comments><description>&lt;p&gt;This happens to be the first PDC for me. This year a lot of new technologies has been unveiled during the keynotes. One of the most focused is the Windows Azure. This happens to be the one stop shop for building and deploying your service oriented application from local to remote. We all know how slow it is to build service oriented application these days and Windows Azure is just the right tool that can make life easier over the course of time. There is a breakout session by Steve Mark that you might like to checkout if you have missed it. The session is a starting point for setting up your first Windows Azure app and it also shows a way to work with Asp.net MVC for things like uploading photos. Also, I found that you can use Azure for building async based queue service easily with asp.net.&lt;/p&gt;  &lt;p&gt;Secondly , with C# 4.0 one of the cool feature that I found is the &lt;em&gt;dynamic&lt;/em&gt; keyword. Let's say you have the following simple class&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Math
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Add (&lt;span class="kwrd"&gt;int&lt;/span&gt; x, &lt;span class="kwrd"&gt;int&lt;/span&gt; y)
    {
         &lt;span class="kwrd"&gt;return&lt;/span&gt; x + y;
    }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;font color="#0000ff"&gt;float&lt;/font&gt; Add (&lt;span class="kwrd"&gt;float&lt;/span&gt; x, &lt;span class="kwrd"&gt;float&lt;/span&gt; y)
    {
         &lt;span class="kwrd"&gt;return&lt;/span&gt; x + y;
    }
}&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;Now , as you can see there are two overloads for&lt;em&gt; Add. &lt;/em&gt;One is with int and another with float. With the current C# 3.5 (for non generic classes) you need to do&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Math math = &lt;span class="kwrd"&gt;new&lt;/span&gt; Math();
Type mType = math.GetType();

&lt;span class="kwrd"&gt;object&lt;/span&gt; result = mType.InvokeMember(&lt;span class="str"&gt;&amp;quot;Add&amp;quot;&lt;/span&gt;, BindingFlags.InvokeMethod, &lt;span class="kwrd"&gt;null&lt;/span&gt;, math, &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt;[] {10, 20});
&lt;span class="kwrd"&gt;object&lt;/span&gt; resultFloat = mType.InvokeMember(&lt;span class="str"&gt;&amp;quot;Add&amp;quot;&lt;/span&gt;, BindingFlags.InvokeMethod, &lt;span class="kwrd"&gt;null&lt;/span&gt;, math, &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt;[] { 10.5f, 20f });

Console.WriteLine(result);
Console.WriteLine(resultFloat);&lt;/pre&gt;

&lt;p&gt;Which of course the only way to call float and int overload depending on value type with existing solution. But with C# 4.0 you can also do the following&lt;/p&gt;

&lt;pre class="csharpcode"&gt;dynamic math= &lt;span class="kwrd"&gt;new&lt;/span&gt; Math();

Console.WriteLine (math.Add (10, 20));
Console.WriteLine (math.Add (10.5f, 20f));&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;As we can see that no &lt;em&gt;invoke &lt;/em&gt;method or &lt;em&gt;generics &lt;/em&gt;is ever required to call overloads with different type.You can find&amp;#160; more interesting stuffs on C# 4.0 from the cool session by Anders Hejlsberg, if you at any chance missed it.&lt;/p&gt;

&lt;p&gt;PDC 2008 is the event for windows 7. It is supplied to all the attendees with the 160GB mobile hard-drive and of course as a DVC copy. The most cool thing is to be able to add &lt;em&gt;vhds&lt;/em&gt; as logical drives and being able to set them as primary drive to boot in native mode. Most of the feature shown in the PDC keynotes are by default in protected mode, so you might need to do tweaks for it.&lt;/p&gt;

&lt;p&gt;Finally, &amp;quot;M&amp;quot; is the language for defining your domain model and &amp;quot;Quadrant&amp;quot; is a nice tool that harnesses the &amp;quot;M&amp;quot; to design and persist complex domain model visually. Together they are the &amp;quot;Oslo&amp;quot; project. Try the three parts session from microsoftPdc dot com.&lt;/p&gt;

&lt;p&gt;In the end, with Microsoft Surface setup in different places of the convention center with people participating in &amp;quot;Scavenger Hunt&amp;quot; challenge, cool product showcase by various players at Microsoft ecosystem and PDC dinner at Universal Studios really made things rocking. May be next PDC will be even more exciting with beta products coming out to life ;).&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6727131" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=25G7wu3T"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=9a16SyB5"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=52" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=x8Sjq4Jh"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=RynPYWpR"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?i=RynPYWpR" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/3MqCYFC7wLU" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/PDC+08/default.aspx">PDC 08</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Windows+7/default.aspx">Windows 7</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Windows+Azure/default.aspx">Windows Azure</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_+4.0/default.aspx">C# 4.0</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2008/11/09/retrospective-of-pdc-2008-from-my-view.aspx</feedburner:origLink></item><item><title>I am here at PDC 2008</title><link>http://feedproxy.google.com/~r/burncsharp/~3/kx9NRewYJd0/i-am-here-at-pdc-2008.aspx</link><pubDate>Sun, 26 Oct 2008 09:50:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6704600</guid><dc:creator>mehfuzh</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6704600</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6704600</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/10/26/i-am-here-at-pdc-2008.aspx#comments</comments><description>&lt;p&gt;&amp;#160;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/IamhereatPDC2008_1F5E/dev_2.jpg"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="dev" src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/IamhereatPDC2008_1F5E/dev_thumb.jpg" width="164" height="220" /&gt;&lt;/a&gt;&lt;/p&gt; Finally, PDC 2008 is going to roll on this Monday, when Ray Ozzie will start the show off with his keynote. This year there will be quite a new things to be announced during the show. There will be first time preview of Windows 7 and Microsoft's new modeling platform Oslo. There will be C# 4.0 talks , Asp.net MVC and more. All these will be covered in couple of keynotes and a load of sessions during the PDC week. Also, there will be some book singing events where Anders Hejlsberg will be signing copies of the C# Programming Language. I am a part of the &lt;a target="_blank" href="http://www.telerik.com/"&gt;Telerik&lt;/a&gt; PDC crew and it is all fun starting from setting up booth (you must try it to feel the joy :-), team work and IKEA stuffs.) with the team and meeting cool dev's. As many of you know that the soft copy of the early build of windows 7 will be delivered though a 160GB mobile hard-rive&amp;#160; which is really cool. Finally, PDC is never been fun without Scott Guthrie, Scott Hanselman, Don Box, Chris Anderson with their cool keynotes and sessions.   &lt;br /&gt;  &lt;br /&gt;This year Microsoft will be focusing on cloud computing platforms (Dublin and .net services), which is growing popular these days with plenty of API's flying around. I will keep you guys what I learn from the event and about cloud computing.   &lt;p&gt;Some of my favorite sessions follows &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Day 1&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Some of my Key interest sessions follows&lt;/p&gt;  &lt;p&gt;TL16 The Future of C# by Anders Hejlsberg&lt;/p&gt;  &lt;p&gt;TL40 &amp;quot;Dublin&amp;quot; and .NET Services: Extending On-Premises Applications to the Cloud&lt;/p&gt;  &lt;p&gt;PC20 ASP.NET 4.0 Roadmap By Scott Hunter&lt;/p&gt;  &lt;p&gt;PC21 ASP.NET MVC: A New Framework for Building Web Applications by Phill Haack&lt;/p&gt;  &lt;p&gt;PC58 Framework Design Guidelines by Brad Adams&lt;/p&gt;  &lt;p&gt;TL49 Microsoft .NET Framework: Overview and Applications for Babies by Scott Hanselman&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Day 2&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;TL27 &amp;quot;Oslo&amp;quot;: The Language by Don Box&lt;/p&gt;  &lt;p&gt;PC31 ASP.NET and JQuery by Stephen Walther&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Day 3&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;BB24 SQL Server 2008: Deep Dive into Spatial Data by Isaac Kunen&lt;/p&gt;  &lt;p&gt;TL18 &amp;quot;Oslo&amp;quot;: Customizing and Extending the Visual Design Experience by Don Box&lt;/p&gt;  &lt;p&gt;PC54 Mono and .NET by Miguel de Icaza&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Day 4&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;TL32 Microsoft Visual Studio: Customizing and Extending the Development Environment&lt;/p&gt;  &lt;p&gt;TL31 &amp;quot;Oslo&amp;quot;: Building Textual DSLs by Chris Anderson&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;These are only few. More I will decide on demand :-)&amp;#160; Apart from PDC I am really enjoying my stay at LA, its a nice place properly choreographed and I like it all. If you are coming to PDC want to say Hi, or you want me to do that as well. I will be around at the Telerik Booth and of course in the sessions and keynote halls. By the way, today I found that there will be Microsoft Surface booth. Therefore, it will be cool to play around them as well.&lt;/p&gt;  &lt;p&gt;If you are not in PDC , don't worry&amp;#160; you can enjoy all of it sitting in-front of your laptop. You can download keynotes and sessions from PDC site. That's all I can remember now and will keep you posted about my experience.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6704600" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=w9sfJ79z"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=5dGO4QVA"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=52" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=mJgmpocY"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=Gkf5oXdE"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?i=Gkf5oXdE" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/kx9NRewYJd0" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/PDC+08/default.aspx">PDC 08</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2008/10/26/i-am-here-at-pdc-2008.aspx</feedburner:origLink></item><item><title>LinqExtender 1.4.2 - Supporting Complex type arguments</title><link>http://feedproxy.google.com/~r/burncsharp/~3/VPVoy0v_m-U/linqextender-1-4-2-supporting-complex-type-arguments.aspx</link><pubDate>Sat, 25 Oct 2008 12:24:32 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6703645</guid><dc:creator>mehfuzh</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6703645</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6703645</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/10/25/linqextender-1-4-2-supporting-complex-type-arguments.aspx#comments</comments><description>&lt;p&gt;I just made a quick update to the existing release of LinqExtender. I recently found a bug while building a feature for FlickrXplorer is that if you use constant type query with orderby clause it does pretty well, but it simply does not do well with complex ones. I have used the same logic that I have used for &lt;em&gt;where&lt;/em&gt; clause arguments. Also, it will be out of the scope for this post to drill it down all the LinqExtender logic fort hat. But I would put a brief overview on it that can help you out while building your own IQueryable implementation.&lt;/p&gt;  &lt;p&gt;If I didn't mentioned in my earlier posts. LinqExtender supports two way orderby in your implemented provider&lt;/p&gt;  &lt;p&gt;First by the object property&amp;#160; while looks like&lt;/p&gt;  &lt;pre class="csharpcode"&gt;var query =  from q &lt;span class="kwrd"&gt;in&lt;/span&gt; bookContext
             orderby q.LastUpdated descending
             select q;&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;In this case, Bucket.OrderByClause will be containing the detail of LastUpdated property and its relation to sorting.&lt;/p&gt;

&lt;p&gt;Now, it is also possible to do &lt;em&gt;orderby&lt;/em&gt; in the following way&lt;/p&gt;

&lt;pre class="csharpcode"&gt;var query =  from q &lt;span class="kwrd"&gt;in&lt;/span&gt; bookContext
             orderby &amp;quot;LastUpdated&amp;quot; descending
             select q;&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;But what about the query with member access. Let's assume that there is a Instance class and inside there is one method which has a local variable that is a Enum and that changes by user input. Finally, it is passed in a LINQ query. &lt;/p&gt;

&lt;pre class="csharpcode"&gt;PhotoOrder order = PhotoOrder.Interestingness;
&lt;span class="rem"&gt;// more code to change it on user provided order by&lt;/span&gt;

var query = (from ph &lt;span class="kwrd"&gt;in&lt;/span&gt; context.Photos
             &lt;span class="kwrd"&gt;where&lt;/span&gt; ph.PhotoSize == PhotoSize.Square
                   &amp;amp;&amp;amp; ph.SearchMode == SearchMode.FreeText
                   &amp;amp;&amp;amp; ph.FilterMode == FilterMode.Safe
                   &amp;amp;&amp;amp; ph.Extras == (ExtrasOption.Views | ExtrasOption.Tags)
                   &amp;amp;&amp;amp; ph.SearchText == key
             orderby order descending
             select ph).Take(pageLen).Skip(index);&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;Now, how to parse this or if any sorts of member access is used ? As we know that LINQ expressions are first translated to &lt;em&gt;MethodCallExpression.&lt;/em&gt;In case for&amp;#160; &lt;em&gt;orderby&lt;/em&gt; the &lt;em&gt;MethodCallExpression.Method.Name &lt;/em&gt;name equals &amp;quot;OrderBy&amp;quot;. Once you found a way to get around it. You can then easily build up an extension method or in my case, I have created an extension method that dynamically gets the value out of the method call argruments.&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;object&lt;/span&gt; GetValueFromExpression(&lt;span class="kwrd"&gt;this&lt;/span&gt; Expression expression)
{
    &lt;span class="kwrd"&gt;object&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = &lt;span class="kwrd"&gt;null&lt;/span&gt;;

    UnaryExpression unaryExpression = GetUnaryExpressionFromMethodCall(expression);
    LambdaExpression lambdaExpression = unaryExpression.Operand &lt;span class="kwrd"&gt;as&lt;/span&gt; LambdaExpression;
    &lt;span class="rem"&gt;// get the value by dynamic invocation, used for getting value for MemberType expression.&lt;/span&gt;
    &lt;span class="kwrd"&gt;value&lt;/span&gt; = Expression.Lambda(lambdaExpression.Body).Compile().DynamicInvoke();
    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;As with the hierarchy expression starts with Unary then goes to Lamda and further down. Once we have the lamda expresion , we can then compile it to method call Delegate , which gives&amp;#160; a nice method named DynamicInvoke that brings out the result. In the code, one more thing that I have done is the extraction of the &lt;em&gt;MethodCallExpression &lt;/em&gt;out of UnaryExpression which brings the following code block&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; UnaryExpression GetUnaryExpressionFromMethodCall(Expression expression)
{
    MethodCallExpression mCall = expression &lt;span class="kwrd"&gt;as&lt;/span&gt; MethodCallExpression;
    UnaryExpression uExp = &lt;span class="kwrd"&gt;null&lt;/span&gt;;

    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Expression exp &lt;span class="kwrd"&gt;in&lt;/span&gt; mCall.Arguments)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (exp &lt;span class="kwrd"&gt;is&lt;/span&gt; UnaryExpression)
        {
            uExp = exp &lt;span class="kwrd"&gt;as&lt;/span&gt; UnaryExpression;
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
        }
        &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (exp &lt;span class="kwrd"&gt;is&lt;/span&gt; MethodCallExpression)
        {
            uExp = GetUnaryExpressionFromMethodCall(exp);
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
        }
    }
    &lt;span class="kwrd"&gt;return&lt;/span&gt; uExp;
}&lt;/pre&gt;

&lt;p&gt;This simple code block reveals one more thing that each method call can be nested and as such for nested case we need to go to the further leaf and fetch the value.So far, this is really useful to me for parsing query expressions with complex member access arguments. But it also gives a way, if you are planning your own IQueryable implementation.&lt;/p&gt;

&lt;p&gt;Moving forward, while working with LinqExtender toolkit, if you like attribute oriented programming, you need to specify and get attributes on objects despite the one defined by the toolkit. That follows&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;LinqVisibleAttrible (Marks a property to be processed by LinqExtender when used in a query) &lt;/li&gt;

  &lt;li&gt;OriginalFieldNameAttribute (Overrides the property name, if data store has a different name) &lt;/li&gt;

  &lt;li&gt;OriginalEnitityNameAttribute (Overrides the class name) &lt;/li&gt;

  &lt;li&gt;UniqueIdentifierAttribtue (Marks a property Unique which is useful for updating object, please see my earlier post). &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So what if you want to have your own and get it in the AddItem, UpdateItem, RemoveItem or Process overrides ? You can do it easily by the following statement.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;// let's say during the add i want to track MyAttribute&lt;/span&gt;
&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; AddItem(Bucket bucket)
{
    MyAttribute attribute = (MyAttribute)item.FindAttribute(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyAttribute)); 
}&lt;/pre&gt;

&lt;p&gt;This is all for now. Before I end, I would like to bring down a brief history how I started &lt;a target="_blank" href="http://www.codeplex.com/LinqExtender"&gt;LinqExtender&lt;/a&gt;. Now, there are pretty good amount of LINQ providers out there and still growing and my motto is to help them get started with no pain.When I stared LinqExtender it came with a handful of features which has grown efficient day by day with the help of community. I build everything that people requests me and sounds logical to roadmap of the project. In the end , the basic concept remains the same from day one which is, &amp;quot;&lt;em&gt;build more LINQ providers with less effort and it takes the most complexity on its own without scarifying features (Ex. projection, complex query parsing, etc)&lt;/em&gt;&amp;quot;. It is basically suited for cloud APIS&amp;#160; like one I have built named &lt;a target="_blank" href="http://www.codeplex.com/LINQFlickr"&gt;Athena (Formarly:LINQ.Flickr)&lt;/a&gt; but can be used with ORMs and core data objects to provide custom LINQ support over legacy interface.&lt;/p&gt;

&lt;p&gt;Hope that helps&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f10%2f25%2flinqextender-1-4-2-supporting-complex-type-arguments.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%2f10%2f25%2flinqextender-1-4-2-supporting-complex-type-arguments.aspx" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6703645" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=ZhPJ7nOs"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=1cmBwbEp"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=52" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=4bqde9EW"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=oUD2fIcQ"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?i=oUD2fIcQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/VPVoy0v_m-U" height="1" width="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><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2008/10/25/linqextender-1-4-2-supporting-complex-type-arguments.aspx</feedburner:origLink></item><item><title>Using jQuery to do Ajax Form posts in Asp.net MVC</title><link>http://feedproxy.google.com/~r/burncsharp/~3/WysODf8GAgc/using-jquery-to-do-ajax-form-posts-in-asp-net-mvc.aspx</link><pubDate>Mon, 13 Oct 2008 16:11:16 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6678289</guid><dc:creator>mehfuzh</dc:creator><slash:comments>4</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6678289</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6678289</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/10/13/using-jquery-to-do-ajax-form-posts-in-asp-net-mvc.aspx#comments</comments><description>&lt;p&gt;It is now official from a post by great &lt;a target="_blank" href="http://weblogs.asp.net/scottgu/"&gt;Scott Guthrie&lt;/a&gt; that jQuery is bundled with Asp.net MVC Beta. jQuery is a tiny 15K JavaScript library that contains features from UI tweaks, DOM manipulation to full Ajax control. In my last post, I have shown how to get going with &lt;em&gt;Ajax.Form using &lt;/em&gt;Microsoft MVC Ajax library. In this post, I will show how to do Ajax form posts with jQuery but in &lt;em&gt;Ajax.Form&lt;/em&gt; style.&lt;/p&gt;  &lt;p&gt;To mark the marriage of jQuery, I have released a new version of FlickrXplorer that uses nothing but jQuery on the client. More info on the release can be found at the following URL.&lt;/p&gt;  &lt;p&gt;&lt;a title="http://www.codeplex.com/FlickrXplorer/Release/ProjectReleases.aspx?ReleaseId=18041" target="_blank" href="http://www.codeplex.com/FlickrXplorer/Release/ProjectReleases.aspx?ReleaseId=18041"&gt;http://www.codeplex.com/FlickrXplorer/Release/ProjectReleases.aspx?ReleaseId=18041&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Ajax.Form&lt;/em&gt; gives a nice way of adding ajax features with no more tears. Just add a &lt;em&gt;using&lt;/em&gt; block with necessary html controls and a submit button, everything else is taken care of on behalf. Being inspired by it, in FlickrXplorer project I have created a &lt;em&gt;Html.JForm&lt;/em&gt; that works in a similar way using jQuery library.&lt;/p&gt;  &lt;p&gt;To see how it works, it is to mention that Ajax.Form basically creates a html form with &lt;em&gt;onsubmit&lt;/em&gt; hook where it injects few JavaScript from Microsoft MVC Ajax Library. To replicate, le's say to do an image list&amp;#160; paging with &lt;em&gt;Html.JForm&lt;/em&gt; that gets the data, shows the loader and updates the container &lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Asp.netMVCAjaxFormpostsusingjQuery_E1B7/image_2.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.netMVCAjaxFormpostsusingjQuery_E1B7/image_thumb.png" width="404" height="306" /&gt;&lt;/a&gt;&amp;#160; &lt;/p&gt;  &lt;p&gt;I first added the MVC JavaScript (Ex. Inside default.master) file with ajax stuffs that works with &lt;em&gt;Html.JForm&lt;/em&gt;&amp;#160; and referenced the jQuery library.&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;jquery-1&lt;/span&gt;.&lt;span class="attr"&gt;2&lt;/span&gt;.&lt;span class="attr"&gt;6&lt;/span&gt;.&lt;span class="attr"&gt;min&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 src=&lt;span class="str"&gt;&amp;quot;&amp;lt;%= Page.ResolveClientUrl(&amp;quot;&lt;/span&gt;~/Content/mvc-jquery.js&lt;span class="str"&gt;&amp;quot;) %&amp;gt;&amp;quot;&lt;/span&gt; type=&lt;span class="str"&gt;&amp;quot;text/javascript&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;p&gt;Finally, In the actual ascx/aspx file, I wrote the following&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; (Html.JForm(VirtualPathUtility.AppendTrailingSlash(HttpContext.Current.Request.Path), &lt;span class="str"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;new&lt;/span&gt; JOptions
    { 
        TargetPanelId = &lt;span class="str"&gt;&amp;quot;imgListContainer&amp;quot;&lt;/span&gt;, 
        WaitPanelId = &lt;span class="str"&gt;&amp;quot;imgListWait&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;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="asp"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="asp"&gt;&lt;/span&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;That's it , also it is to include that this will work with controller actions that return either ContentResult or ActionResult.&lt;/p&gt;

&lt;p&gt;Basically, the signature of &lt;em&gt;Html.JForm&lt;/em&gt; looks like&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Overload 1 : Html.JForm(actionurl, methodType, JOptions);&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;Html.JForm(&lt;span class="str"&gt;&amp;quot;/controller/action&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;GET/POST&amp;quot;&lt;/span&gt;,
&lt;span class="kwrd"&gt;new&lt;/span&gt; JOptions 
{ 
    TargetPanelId = &lt;span class="str"&gt;&amp;quot;update containter&amp;quot;&lt;/span&gt;
    WaitPanelId = &lt;span class="str"&gt;&amp;quot;intermidiate visible panel&amp;quot;&lt;/span&gt;
});&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;Overload 2 : Html.JForm(actionurl, methodType, JOptions, htmlArrributes);&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;Html.JForm(&lt;span class="str"&gt;&amp;quot;/controller/action&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;GET/POST&amp;quot;&lt;/span&gt;,
&lt;span class="kwrd"&gt;new&lt;/span&gt; JOptions 
{ 
    TargetPanelId = &lt;span class="str"&gt;&amp;quot;update containter&amp;quot;&lt;/span&gt;
    WaitPanelId = &lt;span class="str"&gt;&amp;quot;intermidiate visible panel&amp;quot;&lt;/span&gt;
}, &lt;span class="kwrd"&gt;new&lt;/span&gt; { name = &lt;span class="str"&gt;&amp;quot;myForm&amp;quot;&lt;/span&gt; );&lt;/pre&gt;

&lt;p&gt;Going deeper, these are actually &lt;em&gt;HtmlHelper&lt;/em&gt; extenstion methods&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; IDisposable JForm(&lt;span class="kwrd"&gt;this&lt;/span&gt; HtmlHelper helper, &lt;span class="kwrd"&gt;string&lt;/span&gt; action, &lt;span class="kwrd"&gt;string&lt;/span&gt; method, JOptions options, &lt;span class="kwrd"&gt;object&lt;/span&gt; htmlAttribtues)
{
    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; JQueryForm(helper, action, method, options, htmlAttribtues);
}&lt;/pre&gt;

&lt;p&gt;Behind the scene they call a IDisposable class callled JQueryForm that generates the form with actual hookup scripts. The concept is to generate the starting form tag with all the attributes provided during initialization and the ending form tag on dispose call. This basically is done in the Ajax.From that can be found with a little help from &lt;em&gt;reflector.net (or source from codeplex)&lt;/em&gt;. Now, inside &lt;em&gt;System.Web.Mvc&lt;/em&gt; there is a new public class called &lt;em&gt;TagBuilder&lt;/em&gt;, which I found really handy for building up html scripts.&lt;/p&gt;

&lt;p&gt;Therefore, here is what I have done during initialization of JQueryForm. I have added only code that generates the tag, other things you can find it by yourself in the code provided at the end.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;TagBuilder builder = &lt;span class="kwrd"&gt;new&lt;/span&gt; TagBuilder(&lt;span class="str"&gt;&amp;quot;form&amp;quot;&lt;/span&gt;);

builder.MergeAttribute(&lt;span class="str"&gt;&amp;quot;action&amp;quot;&lt;/span&gt;, url);
builder.MergeAttribute(&lt;span class="str"&gt;&amp;quot;method&amp;quot;&lt;/span&gt;, method);
builder.MergeAttributes&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt;(&lt;span class="kwrd"&gt;new&lt;/span&gt; RouteValueDictionary(htmlAttributes));

&lt;span class="kwrd"&gt;if&lt;/span&gt; (options.CallBack == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
{
    builder.MergeAttribute(&lt;span class="str"&gt;&amp;quot;onsubmit&amp;quot;&lt;/span&gt;,
                           &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(jStringOverload, options.WaitPanelId, options.TargetPanelId));
}
&lt;span class="kwrd"&gt;else&lt;/span&gt;
{
    builder.MergeAttribute(&lt;span class="str"&gt;&amp;quot;onsubmit&amp;quot;&lt;/span&gt;,
                           &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(jString, options.WaitPanelId, options.TargetPanelId, options.CallBack));
}

responseBase = helper.ViewContext.HttpContext.Response;
responseBase.Write(builder.ToString(TagRenderMode.StartTag));&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;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;To add attributes MergeAttribute is used that has few overloads and appends the attribute to the generating tag. Finally, to build the string you need to use the ToString overload with proper render mode.I have used TagRenderMode.StartTag which will generate the opening &lt;em&gt;html form&lt;/em&gt; tag.Basically, JQueryForm has only a Constructor where I build starting tag and a Dispose method where I just have to close the tag.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;responseBase.Write(&lt;span class="str"&gt;&amp;quot;&amp;lt;/form&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;As you can see that I have hooked one method in &lt;em&gt;onsubmit&lt;/em&gt; call, the purpose of this method is to prevent default &lt;em&gt;form post,&lt;/em&gt; do an ajax callback and get the result to a html container. I named it &lt;em&gt;jAjaxSubmit.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Before jumping to the analysis of the method, let's see how to do ajax calls using jQuery. It is very clean and simple. Therefore, really cool.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;$(&amp;quot;#&amp;quot; + waitElementId).show();

$.ajax({
    type: actionType,
    dataType: &amp;quot;html&amp;quot;,
    url: url,
    data: params,
    success: function(result) {
        $(&amp;quot;#&amp;quot; + elementId).html(result);
        $(&amp;quot;#&amp;quot; + waitElementId).hide();

        if (typeof callback != 'undefined')
            callback();
    },
    error: function(error) {
        $(&amp;quot;#&amp;quot; + waitElementId).hide();
        //TODO:// write your log here
    }
});&lt;/pre&gt;

&lt;p&gt;This is an example of Ajax callback where I can provide the type [GET|POST], dataType[html|xml|json](i have used &amp;quot;html&amp;quot;), data[serialized form params], success and a failure callback. Those who are new to jQuery, it is to mention that $(..) is equal to the $get in Microsoft Ajax and it accepts element either by id or name (# is used to specify get element by id).&lt;/p&gt;

&lt;p&gt;During the submit button click under &lt;em&gt;Html.JForm&lt;/em&gt; , we first need to stop the &lt;em&gt;form post&lt;/em&gt;. For, Internet Explorer we can do this by sending a &lt;em&gt;return false&lt;/em&gt; but for Mozilla based browsers the proper way to do is the stopPropagation() call.&lt;/p&gt;

&lt;pre class="csharpcode"&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (!$.browser.msie) {
        e.stopPropagation();
    }&lt;/pre&gt;

&lt;p&gt;Inside the using of &lt;em&gt;Html.JForm&lt;/em&gt; as we specify&amp;#160; Html elements either by Html extension methods (&amp;lt;%= Html.Textbox(&amp;quot;comment&amp;quot;) %&amp;gt;) or by hand. we need to get the values of them and pass them as &amp;quot;&amp;amp;&amp;quot; separated way during the submit process. using JQuery, we can easily do that using $(form).serialize() and pass it in the callback. So the final script looks like&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;function&lt;/span&gt; jAjaxSubmit(form, e, waitPanelId, targetToUpdate, methodName) {

&lt;span class="kwrd"&gt;if&lt;/span&gt; (!$.browser.msie) {
    e.stopPropagation();
}
&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;) {
    isValid = methodName(form, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
}

&lt;span class="kwrd"&gt;if&lt;/span&gt; (isValid) {
    &lt;span class="rem"&gt;// create the form body&lt;/span&gt;
    &lt;span class="kwrd"&gt;var&lt;/span&gt; body = $(form).serialize();
    renderContent2(targetToUpdate, waitPanelId, form.action, body, form.method);
}
&lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;/pre&gt;

&lt;pre class="csharpcode"&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;em&gt;renderContent2&lt;/em&gt; is just a wrap around of the callback script shown earlier. In running project, injected block looks like the following &lt;em&gt;firebug&lt;/em&gt; snap.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Asp.netMVCAjaxFormpostsusingjQuery_E1B7/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.netMVCAjaxFormpostsusingjQuery_E1B7/image_thumb_1.png" width="620" height="83" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Apart from the internals , all things are done automatically by &lt;em&gt;Html.JForm&lt;/em&gt; call, this can be found running in FlickrXplorer project but for your convenience, I have added a sample project using the default MVC template which you can get &lt;a target="_blank" href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/Asp.netMVCAjaxFormpostsusingjQuery_E1B7/MVCJQuery.Sample.zip"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Of course, you can try browsing the live app at &lt;a target="_blank" href="http://www.flickrmvc.net"&gt;http://www.flickrmvc.net&lt;/a&gt; (This gives you a nice way to fast explore millions cool public photos from flickr).&lt;/p&gt;

&lt;p&gt;Have Fun!!!&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff0000"&gt;Updated with Asp.net MVC Beta on Oct 19, 2008&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%2f10%2f13%2fusing-jquery-to-do-ajax-form-posts-in-asp-net-mvc.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%2f10%2f13%2fusing-jquery-to-do-ajax-form-posts-in-asp-net-mvc.aspx" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6678289" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=xotNcYKr"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=WcYCoCwM"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=52" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=CmMqIuWr"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=fwGH5N5g"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?i=fwGH5N5g" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/WysODf8GAgc" height="1" width="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/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><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/jQuery/default.aspx">jQuery</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2008/10/13/using-jquery-to-do-ajax-form-posts-in-asp-net-mvc.aspx</feedburner:origLink></item><item><title>Asp.net MVC more Form post scenarios and Ajax</title><link>http://feedproxy.google.com/~r/burncsharp/~3/bS1LshpFUls/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>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6645726</wfw:commentRss><wfw:comment>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;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=NvvI8H4R"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=41" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=t6dZo5oC"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=52" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=MDG4ZTTS"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?d=50" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/burncsharp?a=0Z0K8H3Z"&gt;&lt;img src="http://feeds.feedburner.com/~f/burncsharp?i=0Z0K8H3Z" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/bS1LshpFUls" height="1" width="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><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2008/09/29/asp-net-mvc-more-form-post-scenarios-and-ajax.aspx</feedburner:origLink></item></channel></rss>
