<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://ilovevb.net/Web/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Fun with VB LINQ</title><subtitle type="html" /><id>http://ilovevb.net/Web/blogs/linq/atom.aspx</id><link rel="alternate" type="text/html" href="http://ilovevb.net/Web/blogs/linq/default.aspx" /><link rel="self" type="application/atom+xml" href="http://ilovevb.net/Web/blogs/linq/atom.aspx" /><generator uri="http://communityserver.org" version="3.1.20917.1142">Community Server</generator><updated>2008-03-24T12:53:00Z</updated><entry><title>LINQ and AJAX webinar sample code</title><link rel="alternate" type="text/html" href="http://ilovevb.net/Web/blogs/linq/archive/2008/03/25/linq-and-ajax-webinar-sample-code.aspx" /><id>http://ilovevb.net/Web/blogs/linq/archive/2008/03/25/linq-and-ajax-webinar-sample-code.aspx</id><published>2008-03-25T18:35:00Z</published><updated>2008-03-25T18:35:00Z</updated><content type="html">&lt;p&gt;This is the sample code used in the 3 demos I did today (3/25/08) for the Magenic Webinar on Visual Studio 2008.&amp;nbsp; &lt;b&gt;&lt;a href="http://ilovevb.net/Web/files/folders/linq/entry121.aspx"&gt;Grab it here.&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;The archive contains a solution with 2 aspx pages and the related VB codebehind files.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;You should be able to look at the query and get a good idea of the schema of the Person table. (ID, LName, FName, City, State)&amp;nbsp;&lt;/p&gt;&lt;p&gt;There are two &amp;quot;regions&amp;quot; in the default.aspx page.&amp;nbsp; One is just regular HTML, and the other has an AJAX UpdatePanel and a ScriptManager control.&amp;nbsp; Anything you want to &amp;quot;AJAXify&amp;quot; needs to go inside the update panel (near the bottom half of the page.)&lt;/p&gt;&lt;p&gt;The Default.aspx page is used for the first two demos, and the LINQToObjects.aspx page is used for the 3rd demo.&amp;nbsp;&lt;/p&gt;&lt;p&gt;If you have any questions, please post a comment.&amp;nbsp;&lt;/p&gt;&lt;img src="http://ilovevb.net/Web/aggbug.aspx?PostID=120" width="1" height="1"&gt;</content><author><name>admin</name><uri>http://ilovevb.net/Web/members/admin.aspx</uri></author><category term="LINQ" scheme="http://ilovevb.net/Web/blogs/linq/archive/tags/LINQ/default.aspx" /><category term="SQL" scheme="http://ilovevb.net/Web/blogs/linq/archive/tags/SQL/default.aspx" /><category term="AJAX" scheme="http://ilovevb.net/Web/blogs/linq/archive/tags/AJAX/default.aspx" /><category term="VB.NET" scheme="http://ilovevb.net/Web/blogs/linq/archive/tags/VB.NET/default.aspx" /></entry><entry><title>Deferred Execution</title><link rel="alternate" type="text/html" href="http://ilovevb.net/Web/blogs/linq/archive/2008/03/24/deferred-execution.aspx" /><id>http://ilovevb.net/Web/blogs/linq/archive/2008/03/24/deferred-execution.aspx</id><published>2008-03-24T16:57:00Z</published><updated>2008-03-24T16:57:00Z</updated><content type="html">&lt;p&gt;Here&amp;#39;s a quick and dirty&amp;nbsp;example of LINQ to Objects that my friend Justin showed me. Actually, he showed me in C#, but it took all of about 45 seconds to rewrite it in VB.NET so here it is:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. Create an ASPX page in Visual Studio and add a GridView Control. Leave the name as GridView1.&lt;br /&gt;&lt;/strong&gt;(You can do this any number of ways, like a console app, but I happened to do it in an aspx page.)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. In your codebehind page, add the following to the form1.Load event:&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim filter As String = &amp;quot;System&amp;quot; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim query = From a In AppDomain.CurrentDomain.GetAssemblies() _ &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Where a.GetName().Name.Contains(filter) _ &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Select a.GetName.Name &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#39;filter = &amp;quot;Xml&amp;quot; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; GridView1.DataSource = query &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; GridView1.DataBind() &lt;br /&gt;End Sub &lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;Be sure to leave the &amp;#39;filter = &amp;quot;Xml&amp;quot; line commented out for now, we&amp;#39;ll come back to that in a minute!!&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Now run the page. You should see something that looks like this:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/cwilliams/WindowsLiveWriter/DeferredExecutioninLINQ_FE1C/image_2.png"&gt;&lt;img style="BORDER-TOP-WIDTH:0px;BORDER-LEFT-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-RIGHT-WIDTH:0px;" height="531" alt="image" src="http://geekswithblogs.net/images/geekswithblogs_net/cwilliams/WindowsLiveWriter/DeferredExecutioninLINQ_FE1C/image_thumb.png" width="278" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;You should be looking at a list of Namespaces that begin with &amp;quot;System.&amp;quot;&amp;nbsp; Once you&amp;#39;re done ooh&amp;#39;ing and ahh&amp;#39;ing over it, go back to your codebehind page and... &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. uncomment the &amp;#39;filter = &amp;quot;Xml&amp;quot; line.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Now you&amp;#39;re probably thinking, so what Chris, it&amp;#39;s not going to do anything because it&amp;#39;s AFTER the query...&amp;nbsp; But that is where you&amp;#39;d be wrong. Suspend your disbelief for a moment and take my word for it. I&amp;#39;ll explain in a second.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;So, if you uncomment that line, and run the code again, this time you should see something like this:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/cwilliams/WindowsLiveWriter/DeferredExecutioninLINQ_FE1C/image_4.png"&gt;&lt;img style="BORDER-TOP-WIDTH:0px;BORDER-LEFT-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-RIGHT-WIDTH:0px;" height="267" alt="image" src="http://geekswithblogs.net/images/geekswithblogs_net/cwilliams/WindowsLiveWriter/DeferredExecutioninLINQ_FE1C/image_thumb_1.png" width="286" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;I know, crazy huh?&lt;/strong&gt;&lt;/p&gt;&lt;strong&gt;
&lt;p&gt;&lt;/strong&gt;&lt;strong&gt;What happens is this... when you create your query, it&amp;#39;s not actually executing until you need it. In this case, it&amp;#39;s the databind. In other cases, it might be when you call the .ToArray method of your resultset, or when you add the contents to a custom object, or the .Count method, etc...&lt;/strong&gt;&lt;/p&gt;&lt;strong&gt;
&lt;p&gt;&lt;strong&gt;See... there&amp;#39;s this thing called Deferred Execution, and it&amp;#39;s part of LINQ. It gives us a lot of flexibility. If you need to stick different peices of data from the same source in multiple places, for example, build your query, databind your grid, change that ONE line of code, databind your other grid... awesome, huh?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;/strong&gt;&lt;strong&gt;Enjoy!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(For a much more detailed explanation, I recommend heading over to this MSDN article:&amp;nbsp; &lt;/em&gt;&lt;a class="" href="http://msdn2.microsoft.com/en-us/library/ms364068(vs.80).aspx"&gt;&lt;em&gt;Overview of Visual Basic 9.0&lt;/em&gt;&lt;/a&gt;&lt;em&gt;&amp;nbsp; It&amp;#39;s about 2/3rds of the way down, but the whole article is good reading. It&amp;#39;s by Erik Meijer, Amanda Silver, and Paul Vick.)&lt;/em&gt;&lt;/p&gt;&lt;img src="http://ilovevb.net/Web/aggbug.aspx?PostID=118" width="1" height="1"&gt;</content><author><name>admin</name><uri>http://ilovevb.net/Web/members/admin.aspx</uri></author><category term="LINQ" scheme="http://ilovevb.net/Web/blogs/linq/archive/tags/LINQ/default.aspx" /><category term="Deferred Execution" scheme="http://ilovevb.net/Web/blogs/linq/archive/tags/Deferred+Execution/default.aspx" /><category term="VB9" scheme="http://ilovevb.net/Web/blogs/linq/archive/tags/VB9/default.aspx" /></entry><entry><title>Fun with VB LINQ</title><link rel="alternate" type="text/html" href="http://ilovevb.net/Web/blogs/linq/archive/2008/03/24/fun-with-vb-linq.aspx" /><id>http://ilovevb.net/Web/blogs/linq/archive/2008/03/24/fun-with-vb-linq.aspx</id><published>2008-03-24T16:53:00Z</published><updated>2008-03-24T16:53:00Z</updated><content type="html">&lt;p&gt;I&amp;#39;ve spent the last few weeks working on some demos for VB LINQ (among other things)&amp;nbsp;and once I got the hang of it, rather enjoyed it. &lt;/p&gt;
&lt;p&gt;So, I decided to set up this blog to document some of the neat stuff I&amp;#39;ve learned. As I continue to play and find all the various things you can LINQ to, I&amp;#39;ll add them to this blog. I&amp;#39;ll also be posting any code samples in the related file section, as well as this blog, so you can just download them and start working with them right away.&lt;/p&gt;&lt;img src="http://ilovevb.net/Web/aggbug.aspx?PostID=117" width="1" height="1"&gt;</content><author><name>admin</name><uri>http://ilovevb.net/Web/members/admin.aspx</uri></author><category term="LINQ" scheme="http://ilovevb.net/Web/blogs/linq/archive/tags/LINQ/default.aspx" /></entry></feed>