<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Tanzim Saqib on .NET discovery &#187; LINQ</title>
	<atom:link href="http://tanzimsaqib.wordpress.com/category/linq/feed/" rel="self" type="application/rss+xml" />
	<link>http://tanzimsaqib.wordpress.com</link>
	<description>Innovate. Create. Share.</description>
	<lastBuildDate>Wed, 19 Nov 2008 10:04:28 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='tanzimsaqib.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/756ba5f132c23525771f86885e65d27c?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Tanzim Saqib on .NET discovery &#187; LINQ</title>
		<link>http://tanzimsaqib.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://tanzimsaqib.wordpress.com/osd.xml" title="Tanzim Saqib on .NET discovery" />
		<item>
		<title>LINQ to Flickr</title>
		<link>http://tanzimsaqib.wordpress.com/2008/03/01/linq-to-flickr/</link>
		<comments>http://tanzimsaqib.wordpress.com/2008/03/01/linq-to-flickr/#comments</comments>
		<pubDate>Sat, 01 Mar 2008 16:06:30 +0000</pubDate>
		<dc:creator>tanzimsaqib</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://tanzimsaqib.wordpress.com/2008/03/01/linq-to-flickr/</guid>
		<description><![CDATA[One of my colleagues Mehfuz Hossain developed a wonderful open source project which allows you to query Flickr photos by LINQ, also lets you insert, delete photos directly to/from Flickr. You wonder how to extend LINQ in such an amazing way? It’s easy by writing your own custom LINQ provider, which was not-so-easy until he [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=61&subd=tanzimsaqib&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>One of my colleagues <a href="http://weblogs.asp.net/mehfuzh">Mehfuz Hossain</a> developed a wonderful open source project which allows you to query Flickr photos by LINQ, also lets you insert, delete photos directly to/from Flickr. You wonder how to extend LINQ in such an amazing way? It’s easy by writing your own custom LINQ provider, which was not-so-easy until he came up with another handy open source project named <a href="http://www.codeplex.com/linqextender">LINQ Extender</a><a href="http://www.codeplex.com/linqextender"></a>. He did all the expression parsing stuff to ease our pain. Now you can make your own LINQ to Anything using this so easily.
<p>For your heads up on LINQ extenders, here <a href="http://dotnetslackers.com/articles/csharp/CreatingCustomLINQProviderUsingLinqExtender.aspx">he wrote an article</a> and <a href="http://www.codeplex.com/LINQFlickr">LINQ to Flickr</a>, open source project is hosted at Codeplex.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/tanzimsaqib.wordpress.com/61/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/tanzimsaqib.wordpress.com/61/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tanzimsaqib.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tanzimsaqib.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tanzimsaqib.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tanzimsaqib.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tanzimsaqib.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tanzimsaqib.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tanzimsaqib.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tanzimsaqib.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tanzimsaqib.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tanzimsaqib.wordpress.com/61/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=61&subd=tanzimsaqib&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tanzimsaqib.wordpress.com/2008/03/01/linq-to-flickr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d65a9fc0993ccb92b3897422dbf28d84?s=96&#38;d=identicon" medium="image">
			<media:title type="html">tanzimsaqib</media:title>
		</media:content>
	</item>
		<item>
		<title>A &quot;transactional&quot; generic DbHelper for LINQ to SQL</title>
		<link>http://tanzimsaqib.wordpress.com/2008/02/06/a-transactional-generic-dbhelper-for-linq-to-sql/</link>
		<comments>http://tanzimsaqib.wordpress.com/2008/02/06/a-transactional-generic-dbhelper-for-linq-to-sql/#comments</comments>
		<pubDate>Wed, 06 Feb 2008 07:35:10 +0000</pubDate>
		<dc:creator>tanzimsaqib</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://tanzimsaqib.wordpress.com/2008/02/06/a-transactional-generic-dbhelper-for-linq-to-sql/</guid>
		<description><![CDATA[In LINQ to SQL, the data model of a relational database is mapped to an object model expressed in the programming language of the developer. When the application runs, LINQ to SQL translates into SQL the language-integrated queries in the object model and sends them to the database for execution. When the database returns the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=59&subd=tanzimsaqib&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In LINQ to SQL, the data model of a relational database is mapped to an object model expressed in the programming language of the developer. When the application runs, LINQ to SQL translates into SQL the language-integrated queries in the object model and sends them to the database for execution. When the database returns the results, LINQ to SQL translates them back to objects that you can work with in your own programming language. You may want to make a data access layer that separates the data operation from business layer like the following:</p>
<pre>DbHelper.Insert&lt;<font color="#2b91af">Student</font>&gt;(
    new <font color="#2b91af">Student</font>()
    {
        FirstName = <span style="color:#a31515;">"Tanzim"</span>,
        LastName = <span style="color:#a31515;">"Saqib"</span>,
        Email = <span style="color:#a31515;">"me@TanzimSaqib.com"</span>,
        Website = <span style="color:#a31515;">"http://www.TanzimSaqib.com"</span></pre>
<pre>}, <span style="color:blue;">true</span>);    <span style="color:green;">// Use Transaction?</span></pre>
<p><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></p>
<p>To make use of such transactional generic DbHelper, you might want to write a singeton DbHelper class like the following. You might notice that the class is singleton, it&#8217;s static and the DataContext is being used is private, and only initialized using the connection string if not yet.</p>
<pre><span style="color:blue;">public static class </span><span style="color:#2b91af;">DbHelper
</span>{
    <span style="color:blue;">private const string </span>CONNECTION_CONFIG_NAME = <span style="color:#a31515;">"StudentServerConnectionString"</span>;

    <span style="color:blue;">private static </span>StudentServerDataContext _StudentServerDataContext = <span style="color:blue;">null</span>;

    <span style="color:blue;">public static </span>StudentServerDataContext GetDataContext()
    {
        <span style="color:blue;">if</span>(_StudentServerDataContext == <span style="color:blue;">null</span>)
            _StudentServerDataContext = <span style="color:blue;">new </span>StudentServerDataContext
                (<span style="color:#2b91af;">ConfigurationManager</span>.ConnectionStrings
                [CONNECTION_CONFIG_NAME].ConnectionString);

        <span style="color:blue;">return </span>_StudentServerDataContext;
    }

    <span style="color:blue;">public static void </span>CleanUp()
    {
        _StudentServerDataContext.Dispose();
        _StudentServerDataContext = <span style="color:blue;">null</span>;
    }

    <span style="color:green;">// ... code edited to save space</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>On application wide error or on end you can dispose the context so CleanUp method is useful here. To implement an Insert method see the following. You will find I have used a TransactionScope which ensures that the transaction is taking place without any interruption. If there is really any error the scope.Complete() method never gets invoked. This is how it ensures that the code inside the TransactionScope is taking place as a transaction. It is available from .NET 2.0 framework.</p>
<pre><span style="color:blue;">public static void </span>Insert&lt;T&gt;(T t, <span style="color:blue;">bool </span>isTransactional) <span style="color:blue;">where </span>T : <span style="color:blue;">class
</span>{
    <span style="color:blue;">if </span>(isTransactional)
    {
        <span style="color:blue;">using </span>(<span style="color:blue;">var </span>scope = <span style="color:blue;">new </span><span style="color:#2b91af;">TransactionScope</span>())
        {
            Insert&lt;T&gt;(t);

            <span style="color:green;">// On any Exception, Complete() method won't be invoked.
            // So, the transaction will be automatically rollbacked.
            </span>scope.Complete();
        }
    }
    <span style="color:blue;">else
        </span>Insert&lt;T&gt;(t);
}

<span style="color:blue;">public static void </span>Insert&lt;T&gt;(T t) <span style="color:blue;">where </span>T : <span style="color:blue;">class
</span>{
    <span style="color:blue;">using </span>(<span style="color:blue;">var </span>db = GetDataContext())
    {
        db.GetTable&lt;T&gt;().InsertOnSubmit(t);

        <span style="color:blue;">try
        </span>{
            db.SubmitChanges();
        }
        <span style="color:blue;">catch </span>(<span style="color:#2b91af;">Exception </span>e)
        {
            <span style="color:green;">// TODO: log Exception
            </span><span style="color:blue;">throw </span>e;
        }
    }
}</pre>
<p>I did not show other methods as part of the CRUD implementation. The rest is left open for you to implement.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/tanzimsaqib.wordpress.com/59/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/tanzimsaqib.wordpress.com/59/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tanzimsaqib.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tanzimsaqib.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tanzimsaqib.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tanzimsaqib.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tanzimsaqib.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tanzimsaqib.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tanzimsaqib.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tanzimsaqib.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tanzimsaqib.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tanzimsaqib.wordpress.com/59/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=59&subd=tanzimsaqib&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tanzimsaqib.wordpress.com/2008/02/06/a-transactional-generic-dbhelper-for-linq-to-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d65a9fc0993ccb92b3897422dbf28d84?s=96&#38;d=identicon" medium="image">
			<media:title type="html">tanzimsaqib</media:title>
		</media:content>
	</item>
		<item>
		<title>[New Article] 7 ways to do Performance Optimization of an ASP.NET 3.5 Web 2.0 portal</title>
		<link>http://tanzimsaqib.wordpress.com/2008/02/05/new-article-7-ways-to-do-performance-optimization-of-an-aspnet-35-web-20-portal/</link>
		<comments>http://tanzimsaqib.wordpress.com/2008/02/05/new-article-7-ways-to-do-performance-optimization-of-an-aspnet-35-web-20-portal/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 05:31:00 +0000</pubDate>
		<dc:creator>tanzimsaqib</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://tanzimsaqib.wordpress.com/2008/02/05/new-article-7-ways-to-do-performance-optimization-of-an-aspnet-35-web-20-portal/</guid>
		<description><![CDATA[Web 2.0 applications are widely developed. These applications often work with third party contents, aggregate them, make various use of them and then make something useful and meaningful to the users. For the past few years, developers were also engaged with such endeavors and a lot of their websites have not addressed performance issues, thus [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=58&subd=tanzimsaqib&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Web 2.0 applications are widely developed. These applications often work with third party contents, aggregate them, make various use of them and then make something useful and meaningful to the users. For the past few years, developers were also engaged with such endeavors and a lot of their websites have not addressed performance issues, thus resulting in an unpleasant experience to the users.</p>
<p>Performance is a vast area and great results can never be achieved by a silver bullet. <a href="http://dotnetslackers.com/articles/aspnet/SevenWaysToDoPerformanceOptimizationOfAnASPNET35Web20Portal.aspx" target="_blank">This article</a> explores some of the key performance issues that can occur while developing a Web 2.0 portal using server side multithreading and caching. It also demonstrates model driven application development using Windows Workflow Foundation. </p>
<p>URL: <a title="http://dotnetslackers.com/articles/aspnet/SevenWaysToDoPerformanceOptimizationOfAnASPNET35Web20Portal.aspx" href="http://dotnetslackers.com/articles/aspnet/SevenWaysToDoPerformanceOptimizationOfAnASPNET35Web20Portal.aspx">http://dotnetslackers.com/articles/aspnet/SevenWaysToDoPerformanceOptimizationOfAnASPNET35Web20Portal.aspx</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/tanzimsaqib.wordpress.com/58/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/tanzimsaqib.wordpress.com/58/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tanzimsaqib.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tanzimsaqib.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tanzimsaqib.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tanzimsaqib.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tanzimsaqib.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tanzimsaqib.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tanzimsaqib.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tanzimsaqib.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tanzimsaqib.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tanzimsaqib.wordpress.com/58/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=58&subd=tanzimsaqib&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tanzimsaqib.wordpress.com/2008/02/05/new-article-7-ways-to-do-performance-optimization-of-an-aspnet-35-web-20-portal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d65a9fc0993ccb92b3897422dbf28d84?s=96&#38;d=identicon" medium="image">
			<media:title type="html">tanzimsaqib</media:title>
		</media:content>
	</item>
		<item>
		<title>LINQ: Iterate through collection which implements IEnumerable only</title>
		<link>http://tanzimsaqib.wordpress.com/2007/10/12/linq-iterate-through-collection-which-implements-ienumerable-only/</link>
		<comments>http://tanzimsaqib.wordpress.com/2007/10/12/linq-iterate-through-collection-which-implements-ienumerable-only/#comments</comments>
		<pubDate>Fri, 12 Oct 2007 21:06:25 +0000</pubDate>
		<dc:creator>tanzimsaqib</dc:creator>
				<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://tanzimsaqib.wordpress.com/2007/10/12/linq-iterate-through-collection-which-implements-ienumerable-only/</guid>
		<description><![CDATA[The following works fine in LINQ, because an array implements IEnumerable &#60;T&#62;.
string[] tokenArray = new string[2] { "Hello", "World" };
var tokens = from token in tokenList select token;              

foreach (var item in tokens)
    Console.WriteLine(item);
But, the collections which do not [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=16&subd=tanzimsaqib&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The following works fine in LINQ, because an array implements IEnumerable &lt;T&gt;.</p>
<pre><span style="color:blue;">string</span>[] tokenArray = <span style="color:blue;">new string</span>[2] { <span style="color:#a31515;">"Hello"</span>, <span style="color:#a31515;">"World" </span>};
var tokens = from token <span style="color:blue;">in </span>tokenList select token;              

<span style="color:blue;">foreach </span>(var item <span style="color:blue;">in </span>tokens)
    Console.WriteLine(item);</pre>
<p>But, the collections which do not implement IEnumerable&lt;T&gt; or IQueryable, can not be iterated in LINQ in the same way. To achieve the same, make use of a simple casting trick such as:</p>
<pre>ArrayList tokenList = <span style="color:blue;">new </span>ArrayList();
tokenList.Add(<span style="color:#a31515;">"Hello"</span>);
tokenList.Add(<span style="color:#a31515;">"World"</span>);              

var tokens = from <span style="color:blue;"><strong>string</strong> </span>token <span style="color:blue;">in </span>tokenList select token;              

<span style="color:blue;">foreach </span>(var item <span style="color:blue;">in </span>tokens)
    Console.WriteLine(item);</pre>
<p><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/tanzimsaqib.wordpress.com/16/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/tanzimsaqib.wordpress.com/16/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tanzimsaqib.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tanzimsaqib.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tanzimsaqib.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tanzimsaqib.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tanzimsaqib.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tanzimsaqib.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tanzimsaqib.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tanzimsaqib.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tanzimsaqib.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tanzimsaqib.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tanzimsaqib.wordpress.com&blog=1242602&post=16&subd=tanzimsaqib&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://tanzimsaqib.wordpress.com/2007/10/12/linq-iterate-through-collection-which-implements-ienumerable-only/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d65a9fc0993ccb92b3897422dbf28d84?s=96&#38;d=identicon" medium="image">
			<media:title type="html">tanzimsaqib</media:title>
		</media:content>
	</item>
	</channel>
</rss>