{"id":24,"date":"2008-01-13T21:37:04","date_gmt":"2008-01-13T19:37:04","guid":{"rendered":"http:\/\/jsiegmund.wordpress.com\/2008\/01\/13\/my-first-linq-steps\/"},"modified":"2013-04-18T18:54:35","modified_gmt":"2013-04-18T17:54:35","slug":"my-first-linq-steps","status":"publish","type":"post","link":"http:\/\/blog.repsaj.nl\/index.php\/2008\/01\/my-first-linq-steps\/","title":{"rendered":"My first Linq steps"},"content":{"rendered":"<p>First of all, I would like to wish you all a happy new year. I know it&#8217;s a bit late for that, but I didn&#8217;t get (or take&#8230;)\u00a0a chance to post my first blogpost of 2008 earlier. I&#8217;m eager to find out what this next year is going to bring us, but I guess I&#8217;ll have to wait another 11 1\/2 months to be sure \ud83d\ude09<\/p>\n<p>Now, to start off the new year with some tech-talk, I wanted to write a little bit about <a href=\"http:\/\/en.wikipedia.org\/wiki\/Linq\">Linq<\/a>. Linq is the new way of talking to your database, as far as Microsoft is concerned. It&#8217;s kind-off a replacement of the DataSet with DataTables and TableAdapters used in .NET 2.0 projects. Replacement might not be the best way of putting it, because as far as I know, Linq doesn&#8217;t really store data the way a DataSet does (keeping DataSets still a very usefull way of storing relational data). <!--more--><\/p>\n<p>So what does Linq do then?\u00a0Well, basically it&#8217;s a layer between your code and the actual database which enables you to access objects in\u00a0an object relational manner without you having to deal with T-SQL statements. This means you don&#8217;t have to worry about creating JOINs, Views, Insert, Update and Delete queries. Linq will take care of that, providing you a consistent way of manipulating data in multiple data storage systems. That&#8217;s right: Linq doesn&#8217;t work with SQL Server only! There are a few different kinds of Linq out there, including SQL, XML, Objects, DataSets (hey they&#8217;re still usefull!) and even Google has it&#8217;s own Linq.<\/p>\n<p>To get an idea of the power of Linq, you can take a look at the <a href=\"http:\/\/www.asp.net\/learn\/linq-videos\">videos<\/a> at asp.net which give a pretty good impression of what you can do (or better: leave out) with Linq. For those of you not wanting to listen to all of the videos, here&#8217;s what I did in my test project.<\/p>\n<p>&#8211; Created a database with some tables and relations; all set up the way you&#8217;re supposed to design a relational\u00a0database<br \/>\n&#8211; Created a new web project in Visual Studio 2008 (you need this for Framework 3.5 related things)<br \/>\n&#8211; Added a Linq document to my project\u00a0(in this case Linq to SQL classes). Offcourse you could and would place it in a separate project normally, your Data Access Layer.<br \/>\n&#8211; Used the Server Explorer to connect to my database and drag &#8216;n drop some tables onto the design surface of the Linq file.<\/p>\n<p>Untill this point all the steps are equal to the steps you would take creating a new project with an ADO.NET DataSet layer, but now you would have to specify a query\u00a0to fetch data, one for updating, one for deleting, etc. Notice I&#8217;m not going to do all\u00a0 this \ud83d\ude42<\/p>\n<p>&#8211; Create a new ASPX page and drop a grid onto it.<br \/>\n&#8211; Configure the datasource of the grid to be a new LinqDataSource and select (after compiling first&#8230;) the newly created Linq object which maps to the table you want to display<br \/>\n&#8211; Run the project!<\/p>\n<p>Now, the neat thing is that Linq is taking care of constructing the correct SQL statements. Even if we turn on things like sorting and paging in our grid; nothing has to change. Linq just alters the SQL query to include the correct sorting, or limits the resultset to return only the results on the page you selected.<\/p>\n<p>Offcourse, the same goes for inserting, updating and deleting items in the database. When bound to a formview for instance, all this is taken care of by Linq and you have no worries whatsoever.<\/p>\n<p>Cool, right? I&#8217;m going to play with it\u00a0a bit more before really putting it to use (we&#8217;re not using VS2008 at the office yet), but I&#8217;m already a big fan to say the least. This is definitely going to be a huge time saver as far as I&#8217;m concerned.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>First of all, I would like to wish you all a happy new year. I know it&#8217;s a bit late for that, but I didn&#8217;t get (or take&#8230;)\u00a0a chance to post my first blogpost of 2008 earlier. I&#8217;m eager to find out what this next year is going to bring us, but I guess I&#8217;ll<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[34],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3KFR1-o","_links":{"self":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts\/24"}],"collection":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/comments?post=24"}],"version-history":[{"count":0,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts\/24\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/media?parent=24"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/categories?post=24"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/tags?post=24"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}