{"id":10381,"date":"2006-09-25T12:39:50","date_gmt":"2006-09-25T12:39:50","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/bharry\/2006\/09\/25\/away-for-a-week\/"},"modified":"2018-08-14T00:34:58","modified_gmt":"2018-08-14T00:34:58","slug":"away-for-a-week","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/bharry\/away-for-a-week\/","title":{"rendered":"Away for a week"},"content":{"rendered":"<p>Sorry you haven&#8217;t heard from me for a while.&nbsp; It&#8217;s been busy.&nbsp; I just got back from Redmond (spent all last week there).&nbsp; I was wrapping up a &#8220;special project&#8221;.&nbsp; Given my background both in CLR and in databases, I was asked to spend a few weeks looking at Linq, Linq to SQL and Linq to Entities and give some feedback.&nbsp; Before that I&#8217;d really been largely ignoring what was going on there &#8211; other than a vague understanding of the problem space.\nWow!&nbsp; It&#8217;s really pretty cool stuff.&nbsp; When it comes to SQL, I tend to be very server focused.&nbsp; In TFS, the vast majority of our SQL is in sprocs on the server and very little is dynamic SQL generated by the mid tier.&nbsp; Today, Linq&#8217;s place is really in the later category.&nbsp; I&#8217;ve got to tell you though that when you are in that later category, Linq has a lot to bring to the table.\nI spent a little bit of time playing around with the Linq &amp; ADO.NET CTPs and wrote some pretty cool programs.&nbsp; The abstraction of database operations as filters over enumerations and integration with the CLR type system are really powerful.&nbsp; It allows you to do amazing things with virtually no code.&nbsp; The new Linq syntax, allows for intellisense, and a level of compile time validation that are really compelling.&nbsp; Getting runtime errors from improperly formed SQL strings has always been a pain and Linq can make that mostly a thing of the past.\nFor those who haven&#8217;t see Linq before, here is a very simple example that prints all of the commands longer than 60&nbsp;seconds (60,000,000 microseconds :))&nbsp;from a TFS activity log:\nvar commands = from command <span style=\"color: #0000ff\">in<\/span> db.tbl_Command<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where command.ExecutionTime &gt; 60000000<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select command;<\/p>\n<p><span style=\"color: #0000ff\">foreach<\/span> (tbl_Command command <span style=\"color: #0000ff\">in<\/span> commands)<br \/>{<br \/>&nbsp;&nbsp;&nbsp; Console.WriteLine(&#8220;<span style=\"color: #8b0000\">{0} &#8211; {1}<\/span>&#8220;, command.Application, command.Command);<br \/>}\n&nbsp;\nIn case you are curious, that roughly compiles to this:\nMethodInfo get_ExecutionTime = <span style=\"color: #0000ff\">typeof<\/span>(tbl_Command).GetProperty(&#8220;<span style=\"color: #8b0000\">ExecutionTime<\/span>&#8220;).GetGetMethod();<br \/>ParameterExpression expression1 = Expression.Parameter(<span style=\"color: #0000ff\">typeof<\/span>(tbl_Command), &#8220;<span style=\"color: #8b0000\">command<\/span>&#8220;);<br \/>IQueryable&lt;tbl_Command&gt; queryable1 = Queryable.Where&lt;tbl_Command&gt;(<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logging1.tbl_Command,<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb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Constant((<span style=\"color: #0000ff\">long<\/span>) 0x3938700, <span style=\"color: #0000ff\">typeof<\/span>(<span style=\"color: #0000ff\">long<\/span>))),<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: #0000ff\">new<\/span> ParameterExpression[] { expression1 }));<br \/><span style=\"color: #0000ff\">foreach<\/span> (tbl_Command command1 <span style=\"color: #0000ff\">in<\/span> queryable1)<br \/>{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(&#8220;<span style=\"color: #8b0000\">{0} &#8211; {1}<\/span>&#8220;, command1.Application, command1.Command);<br \/>}\nI&#8217;ve got a bunch of new news in my queue to write about. I&#8217;ll try to do several posts in the next few days to let you know about it.\nThanks,<\/p>\n<p>Brian<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sorry you haven&#8217;t heard from me for a while.&nbsp; It&#8217;s been busy.&nbsp; I just got back from Redmond (spent all last week there).&nbsp; I was wrapping up a &#8220;special project&#8221;.&nbsp; Given my background both in CLR and in databases, I was asked to spend a few weeks looking at Linq, Linq to SQL and Linq [&hellip;]<\/p>\n","protected":false},"author":244,"featured_media":14617,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-10381","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"acf":[],"blog_post_summary":"<p>Sorry you haven&#8217;t heard from me for a while.&nbsp; It&#8217;s been busy.&nbsp; I just got back from Redmond (spent all last week there).&nbsp; I was wrapping up a &#8220;special project&#8221;.&nbsp; Given my background both in CLR and in databases, I was asked to spend a few weeks looking at Linq, Linq to SQL and Linq [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/posts\/10381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/users\/244"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/comments?post=10381"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/posts\/10381\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/media\/14617"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/media?parent=10381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/categories?post=10381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/bharry\/wp-json\/wp\/v2\/tags?post=10381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}