<p>Can a LINQ enabled app run on a machine that only has the .NET 2.0 runtime installed?</p>

<p>In theory, LINQ is nothing more than syntactic sugar, and the resulting IL code should look the same as it would have in .NET 2.0.</p>

<p>How can I write LINQ without using the .NET 3.5 libraries? Will it run on .NET 2.0?</p>

[{'answer_id': 2146, 'author': 'Jon Limjap', 'author_id': 372, 'author_profile': 'https://Stackoverflow.com/users/372', 'pm_score': 2, 'selected': False, 'text': '<p>No, because while you thought LINQ is really just syntactic sugar, it actually heavily used expression trees -- a feature absent in .NET 2.0.</p>\n\n<p>That being said .NET 3.5 only builds up on top of .NET 2.0, and that\'s the reason why the IL doesn\'t look "different" or "special".</p>\n\n<p>I do not see a reason why you shouldn\'t just install the .NET 3.5 Framework. Everything .NET 2.0 will work fine on it, promise :)</p>\n'}, {'answer_id': 2147, 'author': 'Michael Stum', 'author_id': 91, 'author_profile': 'https://Stackoverflow.com/users/91', 'pm_score': 6, 'selected': True, 'text': '<p>There are some "Hacks" that involve using a System.Core.dll from the 3.5 Framework to make it run with .net 2.0, but personally I would not want use such a somewhat shaky foundation.</p>\n\n<p>See here: <a href="http://weblogs.asp.net/fmarguerie/archive/2007/09/05/linq-support-on-net-2-0.aspx" rel="noreferrer">LINQ support on .NET 2.0</a></p>\n\n<blockquote>\n  <ol>\n  <li>Create a new console application</li>\n  <li>Keep only System and System.Core as referenced assemblies</li>\n  <li>Set Copy Local to true for System.Core, because it does not exist in .NET 2.0</li>\n  <li>Use a LINQ query in the Main method. For example the one below.</li>\n  <li>Build</li>\n  <li>Copy all the bin output to a machine where only .NET 2.0 is installed</li>\n  <li>Run</li>\n  </ol>\n</blockquote>\n\n<p>(Requires .net 2.0 SP1 and I have no idea if bundling the System.Core.dll violates the EULA)</p>\n'}, {'answer_id': 2148, 'author': 'John Downey', 'author_id': 200, 'author_profile': 'https://Stackoverflow.com/users/200', 'pm_score': 4, 'selected': False, 'text': '<p>In theory yes, provided you distribute the LINQ specific assemblies and any dependencies. However that is in violation of Microsoft\'s licensing. Scott Hanselman wrote a blog post about <a href="http://www.hanselman.com/blog/DeployingASPNETMVCOnASPNET20.aspx" rel="noreferrer">Deploying ASP.NET MVC on ASP.NET 2.0</a> which is similar to what you are wanting to do.</p>\n'}, {'answer_id': 2156, 'author': 'jdecuyper', 'author_id': 296, 'author_profile': 'https://Stackoverflow.com/users/296', 'pm_score': 2, 'selected': False, 'text': '<p>As far as I know the LINQ library is only available since the framework 3.0.\nIf you want to use something similar in the framework 2.0, you would need to rewritte it yourself :) or find a similar third-party library. I only found a bit of information <a href="http://weblogs.asp.net/fmarguerie/archive/2007/09/05/linq-support-on-net-2-0.aspx" rel="nofollow noreferrer">here</a> but it didn\'t convinced me either.</p>\n'}, {'answer_id': 193090, 'author': 'Scott Wisniewski', 'author_id': 1737192, 'author_profile': 'https://Stackoverflow.com/users/1737192', 'pm_score': 3, 'selected': False, 'text': "<p>I'm not sure about C#.</p>\n\n<p>I do know, however, that you can write VB LINNQ code w/out the 3.5 libraries as long as you use the VS 2008 compiler to target the 2.0 framework.</p>\n\n<p>You will, however, have to implement some of the LINQ methods your self.</p>\n\n<p>LINQ uses a syntatic transformation to translate queries into executable code. Basically, it will take code like this:</p>\n\n<pre><code>dim q = from x in xs where x &gt; 2 select x*4;\n</code></pre>\n\n<p>and convert it into code like this:</p>\n\n<pre><code>dim q = xs.where(function(x) x &gt; 2).select(function(x) x * 4);\n</code></pre>\n\n<p>For the LINQ functionality that ships with the 3.5 framework, those methods are implemented as extension methods on either IEnumerable or IQueryable (there's also a bunch of methods that work on data sets too).</p>\n\n<p>The default IEnumerable extension methods are defined in System.Linq.Enumerable and look like this:</p>\n\n<pre><code>&lt;Extension()&gt;\npublic function Select(of T, R)(source as IEnumerable(of T), transform as Func(of T, R)) as IEnumerable(of R)\n\n   'do the transformation...\n\nend function\n</code></pre>\n\n<p>The IQueryable extension methods take expressions trees as arguments, rather than lambdas. They look like this:</p>\n\n<pre><code> &lt;Extension()&gt;\n public function Select(of T, R)(source as IQueryable&lt;T&gt;, transform as Expression(of Func(of T, R))\n     'build a composite IQueryable that contains the expression tree for the transformation\n end function\n</code></pre>\n\n<p>The expression tree versions enable you to get a tree representation of the expressions provided to the clauses which can then be used to generate SQL code (or what ever else you want).</p>\n\n<p>You could probably create your own version of LINQ to objects in about a day or so. It's all pretty straight forward.</p>\n\n<p>If you want to use DLINQ, then things would be a little bit more difficult.</p>\n"}, {'answer_id': 394595, 'author': 'Mauricio Scheffer', 'author_id': 21239, 'author_profile': 'https://Stackoverflow.com/users/21239', 'pm_score': 6, 'selected': False, 'text': '<p>It\'s weird that no one has mentioned <a href="http://www.albahari.com/nutshell/linqbridge.aspx" rel="noreferrer">LINQBridge</a>. This little awesome project is a backport of LINQ (IEnumerable, but without IQueryable) and its dependencies (Func, Action, etc) to .NET 2.0. And:</p>\n\n<blockquote>\n  <p>If your project references LINQBridge\n  during compilation, then it will bind\n  to LINQBridge\'s query operators; if it\n  references System.Core during\n  compilation, then it will bind to\n  Framework 3.5\'s query operators.</p>\n</blockquote>\n'}, {'answer_id': 883745, 'author': 'Lucas', 'author_id': 24231, 'author_profile': 'https://Stackoverflow.com/users/24231', 'pm_score': 3, 'selected': False, 'text': '<p>Short answer:</p>\n\n<ul>\n<li><strong>LINQ to Objects: yes</strong> (<code>IEnumerable&lt;T&gt;</code>)</li>\n<li><strong>LINQ to SQL/Entities: no</strong> (<code>IQueryable&lt;T&gt;</code>)</li>\n<li>LINQ to XML/DataSets: not yet?</li>\n</ul>\n\n<hr>\n\n<p>See <a href="https://stackoverflow.com/questions/173080/c-net-3-0-3-5-features-in-2-0-using-visual-studio-2008">this question</a> about .Net 3.5 features available automatically or with little effort when targetting .Net 2.0 from VS2008.</p>\n\n<p>Basically, anything that is only "syntax sugar" and the new compilers (C# 3.0, VB 9.0) emit as 2.0-compatible IL will work. This includes many features used by LINQ such as anonymous classes, lambdas as anonymous delegates, automatic properties, object initializers, and collection initializers. </p>\n\n<p>Some LINQ features use classes, interfaces, delegates, and extension methods that live in the new 3.5 assemblies (such as System.Core.dll). Redistributing these assemblies is a license violation, but they could be reimplemented. Using extension methods need only that you declare an empty <code>System.Runtime.CompilerServices.ExtensionAttribute</code>. LINQ to Objects relies on <code>IEnumerable&lt;T&gt;</code> extensions and several delegate declarations (the <code>Action&lt;T&gt;</code> and <code>Func&lt;T&gt;</code> families) and have been implemented in <a href="http://www.albahari.com/nutshell/linqbridge.aspx" rel="nofollow noreferrer">LINQBridge</a> (as <a href="https://stackoverflow.com/questions/2138/linq-on-the-net-2-0-runtime/394595#394595">mausch</a> mentioned). LINQ to XML and LINQ to DataSets rely on LINQ to Objects which I guess could also be implemented for .Net 2.0, but I haven\'t seen this done yet.</p>\n\n<p>LINQ to SQL and LINQ to Entities require many new classes (<code>DataContext</code>/<code>ObjectContext</code>, lots of attributes, <code>EntitySet&lt;T&gt;</code>, <code>EntityRef&lt;T&gt;</code>, <code>Link&lt;T&gt;</code>, <code>IQueryable&lt;T&gt;</code>, etc) and expression trees, which, even if somehow reimplemented, will probably require at least .Net 2.0 SP1 to work.</p>\n'}, {'answer_id': 5197992, 'author': 'Stefan Steiger', 'author_id': 155077, 'author_profile': 'https://Stackoverflow.com/users/155077', 'pm_score': 3, 'selected': False, 'text': '<p>You can use the LINQ sources from mono (.NET for Linux) to get LINQ running on .NET 2.0.</p>\n\n<pre><code>IEnumerable&lt;T&gt; : yes \nIQueryable&lt;T&gt;  : yes\nLINQ to XML : has been working in the trunk, but due to further additions, the trunk doesn\'t compile anymore\n</code></pre>\n\n<p>Someone has done it here:<br>\n<a href="http://linq4you.codeplex.com/" rel="nofollow noreferrer">LINQ for .NET 2.0</a></p>\n'}]
['https://Stackoverflow.com/questions/2138', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/373/']