{"id":28795,"date":"2020-06-17T00:00:00","date_gmt":"2020-06-16T22:00:00","guid":{"rendered":"https:\/\/blexin.com\/linq-un-linguaggio-per-domarli-tutti\/"},"modified":"2021-05-20T18:25:43","modified_gmt":"2021-05-20T16:25:43","slug":"linq-a-language-to-rule-them-all","status":"publish","type":"post","link":"https:\/\/blexin.com\/en\/blog-en\/linq-a-language-to-rule-them-all\/","title":{"rendered":"LINQ: a language to rule them all!"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"608\" data-attachment-id=\"26607\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/linq-a-language-to-rule-them-all\/attachment\/2753c67c-ebae-4900-b572-9b4148ce4887-1-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/2753c67c-ebae-4900-b572-9b4148ce4887-1.png?fit=1024%2C608&amp;ssl=1\" data-orig-size=\"1024,608\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"2753c67c-ebae-4900-b572-9b4148ce4887-1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/2753c67c-ebae-4900-b572-9b4148ce4887-1.png?fit=1024%2C608&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/2753c67c-ebae-4900-b572-9b4148ce4887-1.png?resize=1024%2C608&#038;ssl=1\" alt=\"\" class=\"wp-image-26607\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/2753c67c-ebae-4900-b572-9b4148ce4887-1.png 1024w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/2753c67c-ebae-4900-b572-9b4148ce4887-1-980x582.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/2753c67c-ebae-4900-b572-9b4148ce4887-1-480x285.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">One of the peculiarities that distinguish&nbsp;the .NET world from other technological stacks is definitely LINQ, an acronym for Language INtegrated Query. Introduced with the .NET Framework 3.5 and Visual Studio 2008, it is, in fact, the first framework independent of the architecture and integrated within the C # and Visual Basic languages.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With LINQ we can query and manipulate data using a single programming model independent of the various types of sources. To better understand what it is, however, we must take a leap into the past.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the firstest versions of C#, we had to use a&nbsp;<em>for&nbsp;<\/em>or&nbsp;<em>foreach&nbsp;<\/em>loop to iterate over a collection, which, as we know, implements the&nbsp;<em>IEnumerable&nbsp;<\/em>interface, and, for example, find a particular object inside it. The following code returns all the customers of a company, aged between 19 and 36 years (20 &#8211; 35 years):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nclass Customer\n{ \n\u00a0\u00a0\u00a0public int CustomerID { get; set; } \n\u00a0\u00a0\u00a0public String CustomerName { get; set; } \n\u00a0\u00a0\u00a0public int Age { get; set; } \n} \n\u00a0\nclass Program \n{ \n\u00a0\u00a0\u00a0static void Main(string&#x5B;] args) \n\u00a0\u00a0\u00a0{ \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Customer&#x5B;] customerArray = { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0new Customer() { CustomerID = 1, CustomerName = &quot;Joy&quot;, Age = 22 }, \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0new Customer() { CustomerID = 2, CustomerName = &quot;Bob&quot;, Age = 45 }, \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0new Customer() { CustomerID = 3, CustomerName = &quot;Curt&quot;, Age = 25 },\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0};\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Customer&#x5B;] customers = new Customer&#x5B;10]; \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0int i = 0; \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0foreach (Customer cst in customerArray) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (cst.Age &gt; 19 &amp;&amp; cst.Age &lt; 36) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0customers&#x5B;i] = cst; \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0i++; \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\u00a0} \n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">What might be a different approach? Let\u2019s try to get it step by step, starting from the concept of&nbsp;<em>delegate<\/em>. A&nbsp;<em>delegate&nbsp;<\/em>is a type that represents references to methods with the same parameters and returned type. It &#8220;delegates&#8221; to the method to which it aims the execution of the code and we can declare it in this way:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic delegate bool Operations(int number);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">All methods that take in input an integer and return a Boolean can be pointed by this&nbsp;<em>delegate<\/em>. For example, suppose we have a method in a&nbsp;<em>CustomerOperations&nbsp;<\/em>class:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic bool CustomerAgeRangeCheck(int number)\n{\n\u00a0\u00a0\u00a0\u00a0return number &gt; 19 &amp;&amp; number &lt; 36; \n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">We can register one or more methods that will be executed when the&nbsp;<em>delegate<\/em>&nbsp;is executed:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nOperations op = new Operations(CustomerOperations.CustomerAgeRangeCheck);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Or simply:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nOperations op = CustomerOperations.CustomerAgeRangeCheck;\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nop(22);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><em>Delegates&nbsp;<\/em>are used to pass methods as arguments to other methods:&nbsp;<em>event handlers<\/em>&nbsp;and&nbsp;<em>callbacks&nbsp;<\/em>are examples of methods called through&nbsp;<em>delegates<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">C# 2.0 introduced&nbsp;<em>anonymous delegates<\/em>, you can now use an anonymous method to declare and initialize a&nbsp;<em>delegate<\/em>. For example, we can write:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\ndelegate bool CustomerFilters(Customer customer);\n\u00a0\u00a0\nclass CustomerOperations\n{\n\u00a0\u00a0\u00a0\u00a0public static Customer&#x5B;] FindWhere(Customer&#x5B;] customers, CustomerFilters\u00a0 customerFiltersDelegate)\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0int i = 0;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Customer&#x5B;] result = new Customer&#x5B;6];\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0foreach (Customer customer in customers)\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (customerFiltersDelegate(customer))\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0result&#x5B;i] = customer;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0i++;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return result;\n\u00a0\u00a0\u00a0\u00a0}\n}\n\u00a0\u00a0\nclass Program\n{\n\u00a0\u00a0\u00a0\u00a0static void Main(string&#x5B;] args)\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Customer&#x5B;] customers = {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0new Customer() { CustomerID = 1, CustomerName = &quot;Joy&quot;, Age = 22 },\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0new Customer() { CustomerID = 2, CustomerName = &quot;Bob&quot;, Age = 45 },\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0new Customer() { CustomerID = 3, CustomerName = &quot;Curt&quot;, Age = 25 },\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0};\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Customer&#x5B;] filteredCustomersAge = CustomerOperations.FindWhere(customers, delegate (Customer customer)\u00a0 \/\/Using anonimous delegate\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return customer.Age &gt; 19 &amp;&amp; customer.Age &lt; 36;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\n\u00a0\u00a0\u00a0\u00a0}\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">With C # 2.0, we have the advantage of using&nbsp;<em>anonymous delegates<\/em>&nbsp;in searching with different criteria with no need to use a&nbsp;<em>for&nbsp;<\/em>or&nbsp;<em>foreach&nbsp;<\/em>loop. For example, we can use the same delegate function used in the previous example, to find a customer whose &#8220;CustomerID&#8221; is 3 or whose name is &#8220;Bob&#8221;:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nCustomer&#x5B;] filteredCustomersId = CustomerOperations.FindWhere(customers, delegate (Customer customer)\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return customer.CustomerID == 3;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\n\u00a0\nCustomer&#x5B;] filteredCustomersName = CustomerOperations.FindWhere(customers, delegate (Customer customer)\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return customer.CustomerName == &quot;Bob&quot;;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">With the evolution of C#, since the 3.x versions, the Microsoft Team has introduced new features that make the code even more compact and readable. These&nbsp;are in direct support of LINQ to query different types of data sources and obtain the elements resulting in a single instruction.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These features are:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&#8211; The&nbsp;<em>var&nbsp;<\/em>construct, an implicitly typed local variable. It is strongly typed as the type itself had been declared, but it\u2019s the compiler that determines the type using the Type Inference based on the value assigned to it. The following two statements are functionally equivalent:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nvar customerAge = 30; \/\/ Implicitly typed.\nint customerAge = 30; \/\/ Explicitly typed.\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&#8211;&nbsp;<em>Object initializers<\/em>&nbsp;allow you to assign values to all or some of the properties of an object during its creation time, with no need to invoke a constructor followed by assignment instruction lines.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nCustomer customer = new Customer { Age = 30, CustomerName = &quot;Adolfo&quot; };\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Unlike the following code, in the previous case, everything is considered as a single operation.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nCustomer customer = new Customer();\ncustomer.Age = 30; \ncustomer.CustomerName = &quot;Adolfo&quot;;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&#8211;&nbsp;<em>Anonymous types<\/em>, a read-only type that is built by the compiler, and only the compiler knows it. Still, if two or more anonymous&nbsp;<em>object initializers&nbsp;<\/em>in an assembly have a sequence of properties in the same order and with the same names and types, the compiler treats the objects as instances of the same type.&nbsp;<em>Anonymous types<\/em>&nbsp;are a good way to temporarily group a set of properties in the result of a query, without having to define a separate named type.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nvar customer = new { YearsOfFidelity = 10, Name = &quot;Francesco&quot;}; \n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&#8211; Extension methods, which allow you to &#8220;add&#8221; methods to existing types without creating a new derived type, recompiling, or modifying otherwise the original type. Extension methods are static methods, but they are called thanks to the introduced syntactic sugar, as they were instance methods on the extended type.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic static class StringExtensionMethods\n{\n\u00a0\u00a0\u00a0\u00a0public static string ReverseString(this string input)\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (string.IsNullOrEmpty(input)) return &quot;&quot;;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return new string(input.ToCharArray().Reverse().ToArray());\n\u00a0\u00a0\u00a0\u00a0}\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><em>Extension methods<\/em>&nbsp;must be defined in a static class. The first parameter represents the type to be extended and must be preceded by the keyword&nbsp;<em>this<\/em>, further parameters do not need it.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nConsole.WriteLine(&quot;Hello&quot;.ReverseString());\u00a0\u00a0 \/\/olleH\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Note that the first parameter, the one preceded by the&nbsp;<em>this&nbsp;<\/em>modifier, must not be specified in the method call.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&#8211;&nbsp;<em>Lambda expressions<\/em>, anonymous functions that can be passed as a variable or as a parameter in a method call.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\ncustomer =&gt; customer.Age &gt; 19 &amp;&amp; customer.Age &lt; 36;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The =&gt; operator is called&nbsp;<em>lambda operator<\/em>, while&nbsp;<em>customer&nbsp;<\/em>is the input parameter of the function. The part on the right side of&nbsp;<em>lambda operator<\/em>&nbsp;represents the body of the function and the value it returns, in this case a Boolean.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We finally arrive with C# 3.5 version at the introduction of LINQ.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Simplifying, we could say that LINQ is an&nbsp;<em>extension methods<\/em>&nbsp;library for IEnumerable&lt;T&gt; and IQueryable&lt;T&gt; interfaces, which allows us to perform various operations such as filtering, making projections, aggregations and sorting.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We have several LINQ implementations available:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>LINQ to Objects (In-Memory Object Collection)<\/li><li>LINQ to Entities (Entity Framework)<\/li><li>LINQ to SQL (SQL Database)<\/li><li>LINQ to XML (XML Document)<\/li><li>LINQ to DataSet (ADO.Net Dataset)<\/li><li>By implementing IQueryable interface (Other data source)<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In the previous examples, an array was used as a data source, therefore the generic interface IEnumerable&lt;T&lt; is implicitly supported. Types that support IEnumerable&lt;T&gt; or its derived interface, such as the generic IQueryable&lt;T&gt; interface, are called&nbsp;<em>queryable types<\/em>&nbsp;and allow us to execute LINQ queries directly. If the data source is not already in memory as a&nbsp;<em>queryable type<\/em>, the LINQ provider must represent it as such.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As we said, LINQ queries are mostly based on generic types, introduced in version 2.0 of .NET Framework. This means that if you try, for example, to add a Customer object to a List&lt;string&gt; object, an error will be generated at compile-time. It is easy to use generic collections because there\u2019s no need to cast types at run-time.<br>If we prefer, we can avoid the generic syntax by using the&nbsp;<em>var&nbsp;<\/em>keyword of which we spoke previously, which in the following example asks the compiler to deduce the type of a query variable by examining the data source specified in the&nbsp;<em>from&nbsp;<\/em>clause.<br>So let&#8217;s see how we can achieve the same result that in the previous code we obtained using&nbsp;<em>anonymous delegates<\/em>, using a LINQ to Object query, the&nbsp;<em>var&nbsp;<\/em>construct, and a&nbsp;<em>lambda expression<\/em>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nvar filteredCustomersAge = customers.Where(c =&gt; c.Age &gt; 19 &amp;&amp; c.Age &lt; 36);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">This type of syntax is called Method Syntax.<br>In the next example, we\u2019ll use&nbsp;the Query Syntax, a syntax introduced for those who already know the SQL language and would, therefore, feel comfortable with this type of approach:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nvar filteredCustomersAge =\n\u00a0\u00a0\u00a0\u00a0from customer in customers\n\u00a0\u00a0\u00a0\u00a0where customer.Age &gt; 19 &amp;&amp; customer.Age &lt; 36\n\u00a0\u00a0\u00a0\u00a0select customer;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Query Syntax and Method Syntax are semantically identical, and many people find the syntax of queries simpler and easier to read.<br>In Query Syntax, LINQ query operators are converted into calls to the related LINQ&nbsp;<em>extension methods<\/em>&nbsp;at compile-time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the next article, we\u2019ll continue to talk about LINQ!<br>We\u2019ll talk about the IQueryable&lt;T&gt; interface, its related LINQ extension methods, and the differences with IEnumerable&lt;T&gt; interface.<br>We will also see the use&nbsp;of LINQ with data sources from out-memory collections, as in the case of remote databases.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">See you at the next article! Stay Tuned!<\/p>\n\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>Let\u2019s see how LINQ revolutionized the way we access to data in .NET<\/p>\n","protected":false},"author":196716244,"featured_media":26604,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"off","_et_pb_old_content":"","_et_gb_content_width":"","_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_crdt_document":"","inline_featured_image":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_wpas_customize_per_network":false,"jetpack_post_was_ever_published":false},"categories":[688637524],"tags":[688637384,688637385],"class_list":["post-28795","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-en","tag-c-en","tag-linq-en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>LINQ: a language to rule them all! - Blexin<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blexin.com\/en\/blog-en\/linq-a-language-to-rule-them-all\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"LINQ: a language to rule them all! - Blexin\" \/>\n<meta property=\"og:description\" content=\"Let\u2019s see how LINQ revolutionized the way we access to data in .NET\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blexin.com\/en\/blog-en\/linq-a-language-to-rule-them-all\/\" \/>\n<meta property=\"og:site_name\" content=\"Blexin\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-16T22:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-20T16:25:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i1.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/2753c67c-ebae-4900-b572-9b4148ce4887.png?fit=1024%2C608&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"608\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Francesco Vastarella\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Francesco Vastarella\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/linq-a-language-to-rule-them-all\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/linq-a-language-to-rule-them-all\\\/\"},\"author\":{\"name\":\"Francesco Vastarella\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/388dae0ca9df603c88b5e41e29cf2d4d\"},\"headline\":\"LINQ: a language to rule them all!\",\"datePublished\":\"2020-06-16T22:00:00+00:00\",\"dateModified\":\"2021-05-20T16:25:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/linq-a-language-to-rule-them-all\\\/\"},\"wordCount\":1271,\"image\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/linq-a-language-to-rule-them-all\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/2753c67c-ebae-4900-b572-9b4148ce4887.png?fit=1024%2C608&ssl=1\",\"keywords\":[\"C#\",\"Linq\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/linq-a-language-to-rule-them-all\\\/\",\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/linq-a-language-to-rule-them-all\\\/\",\"name\":\"LINQ: a language to rule them all! - Blexin\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/linq-a-language-to-rule-them-all\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/linq-a-language-to-rule-them-all\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/2753c67c-ebae-4900-b572-9b4148ce4887.png?fit=1024%2C608&ssl=1\",\"datePublished\":\"2020-06-16T22:00:00+00:00\",\"dateModified\":\"2021-05-20T16:25:43+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/388dae0ca9df603c88b5e41e29cf2d4d\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/linq-a-language-to-rule-them-all\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/linq-a-language-to-rule-them-all\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/linq-a-language-to-rule-them-all\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/2753c67c-ebae-4900-b572-9b4148ce4887.png?fit=1024%2C608&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/2753c67c-ebae-4900-b572-9b4148ce4887.png?fit=1024%2C608&ssl=1\",\"width\":1024,\"height\":608},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/linq-a-language-to-rule-them-all\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blexin.com\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"LINQ: a language to rule them all!\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/\",\"name\":\"Blexin\",\"description\":\"Con noi \u00e8 semplice\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blexin.com\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/388dae0ca9df603c88b5e41e29cf2d4d\",\"name\":\"Francesco Vastarella\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3b8deedae8f35372d5fba49f918006fb0a58a2943aff6ae52d3ff188e0c441bb?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3b8deedae8f35372d5fba49f918006fb0a58a2943aff6ae52d3ff188e0c441bb?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3b8deedae8f35372d5fba49f918006fb0a58a2943aff6ae52d3ff188e0c441bb?s=96&d=identicon&r=g\",\"caption\":\"Francesco Vastarella\"},\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/author\\\/francesco-vastarellablexin-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"LINQ: a language to rule them all! - Blexin","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blexin.com\/en\/blog-en\/linq-a-language-to-rule-them-all\/","og_locale":"en_US","og_type":"article","og_title":"LINQ: a language to rule them all! - Blexin","og_description":"Let\u2019s see how LINQ revolutionized the way we access to data in .NET","og_url":"https:\/\/blexin.com\/en\/blog-en\/linq-a-language-to-rule-them-all\/","og_site_name":"Blexin","article_published_time":"2020-06-16T22:00:00+00:00","article_modified_time":"2021-05-20T16:25:43+00:00","og_image":[{"width":1024,"height":608,"url":"https:\/\/i1.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/2753c67c-ebae-4900-b572-9b4148ce4887.png?fit=1024%2C608&ssl=1","type":"image\/png"}],"author":"Francesco Vastarella","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Francesco Vastarella","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blexin.com\/en\/blog-en\/linq-a-language-to-rule-them-all\/#article","isPartOf":{"@id":"https:\/\/blexin.com\/en\/blog-en\/linq-a-language-to-rule-them-all\/"},"author":{"name":"Francesco Vastarella","@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/388dae0ca9df603c88b5e41e29cf2d4d"},"headline":"LINQ: a language to rule them all!","datePublished":"2020-06-16T22:00:00+00:00","dateModified":"2021-05-20T16:25:43+00:00","mainEntityOfPage":{"@id":"https:\/\/blexin.com\/en\/blog-en\/linq-a-language-to-rule-them-all\/"},"wordCount":1271,"image":{"@id":"https:\/\/blexin.com\/en\/blog-en\/linq-a-language-to-rule-them-all\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/2753c67c-ebae-4900-b572-9b4148ce4887.png?fit=1024%2C608&ssl=1","keywords":["C#","Linq"],"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/blexin.com\/en\/blog-en\/linq-a-language-to-rule-them-all\/","url":"https:\/\/blexin.com\/en\/blog-en\/linq-a-language-to-rule-them-all\/","name":"LINQ: a language to rule them all! - Blexin","isPartOf":{"@id":"https:\/\/blexin.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blexin.com\/en\/blog-en\/linq-a-language-to-rule-them-all\/#primaryimage"},"image":{"@id":"https:\/\/blexin.com\/en\/blog-en\/linq-a-language-to-rule-them-all\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/2753c67c-ebae-4900-b572-9b4148ce4887.png?fit=1024%2C608&ssl=1","datePublished":"2020-06-16T22:00:00+00:00","dateModified":"2021-05-20T16:25:43+00:00","author":{"@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/388dae0ca9df603c88b5e41e29cf2d4d"},"breadcrumb":{"@id":"https:\/\/blexin.com\/en\/blog-en\/linq-a-language-to-rule-them-all\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blexin.com\/en\/blog-en\/linq-a-language-to-rule-them-all\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blexin.com\/en\/blog-en\/linq-a-language-to-rule-them-all\/#primaryimage","url":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/2753c67c-ebae-4900-b572-9b4148ce4887.png?fit=1024%2C608&ssl=1","contentUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/2753c67c-ebae-4900-b572-9b4148ce4887.png?fit=1024%2C608&ssl=1","width":1024,"height":608},{"@type":"BreadcrumbList","@id":"https:\/\/blexin.com\/en\/blog-en\/linq-a-language-to-rule-them-all\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blexin.com\/en\/"},{"@type":"ListItem","position":2,"name":"LINQ: a language to rule them all!"}]},{"@type":"WebSite","@id":"https:\/\/blexin.com\/en\/#website","url":"https:\/\/blexin.com\/en\/","name":"Blexin","description":"Con noi \u00e8 semplice","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blexin.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/388dae0ca9df603c88b5e41e29cf2d4d","name":"Francesco Vastarella","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3b8deedae8f35372d5fba49f918006fb0a58a2943aff6ae52d3ff188e0c441bb?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3b8deedae8f35372d5fba49f918006fb0a58a2943aff6ae52d3ff188e0c441bb?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3b8deedae8f35372d5fba49f918006fb0a58a2943aff6ae52d3ff188e0c441bb?s=96&d=identicon&r=g","caption":"Francesco Vastarella"},"url":"https:\/\/blexin.com\/en\/author\/francesco-vastarellablexin-com\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/2753c67c-ebae-4900-b572-9b4148ce4887.png?fit=1024%2C608&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pcyUBx-7ur","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/28795","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/users\/196716244"}],"replies":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/comments?post=28795"}],"version-history":[{"count":4,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/28795\/revisions"}],"predecessor-version":[{"id":31822,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/28795\/revisions\/31822"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/media\/26604"}],"wp:attachment":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/media?parent=28795"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/categories?post=28795"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/tags?post=28795"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}