6

I have a project which can only be deployed on a server running .NET 3.0. I desperately want to use LINQ to simplify some excruciatingly tedious logic. Is there a simple way to accomplish this? I'll settle for any syntax.

Thanks a lot

Tushar S
  • 352
  • 1
  • 6
  • 15

3 Answers3

3

Since .NET 2.0 through 3.5 all run on the CLR 2.0, all the LINQ stuff is just a bunch of libraries. If you include the DLLs that are missing on your version of the framework, it will work just fine.

As Patrick says, the key 3.5 DLLs are System.Core.dll (which provided System.Linq) and System.Data.Linq.dll (for Linq-to-SQL).

If you do this, I think you need System.dll from at least .NET 2.0SP1 I believe.

LINQBridge, as cited by Marc, works by re-implementing the functionality but only for Linq-to-Objects I believe.

Another option is to use these same DLLs (System.Core.dll and System.Data.Linq.dll) from the Mono project. They have reimplemented all of LINQ. The Linq-to-Sql stuff is perhaps a little immature but it does have the virtue of working with other databases than just MSSQL.

http://mono-project.com/Main_Page

This removes any question of the legality of distributing Microsoft DLLs with your application.

Justin
  • 8,853
  • 4
  • 42
  • 42
  • When I say that Mono has implemented all of LINQ, I mean that it supports Linq-to-Objects, Linq-to-XML, and Linq-to-Sql (through the DBLinq project). The latest version of Mono (as of July 2010) is 2.6.7 and that is where I would get the assemblies. – Justin Jul 27 '10 at 22:31
  • This is the best answer in the question so far! – Mike Atlas Jul 27 '10 at 22:48
  • 1
    Oh, I should add that you also need System.Xml.Linq.dll if you want to do Linq-to-XML. Patrick tricked me with his Jedi powers. – Justin Jul 28 '10 at 05:45
2

A coworker used LINQBridge and had success.

Marc
  • 9,254
  • 2
  • 29
  • 31
  • wauw nice tool, will check this out – Nealv Jul 27 '10 at 21:57
  • I think @Justin's answer is better (reference the Mono libraries) - If it were me, I'd really like to have LINQ to XML as well. Also, the Mono community is big and active, whereas this is only implemented by one person and I can't even tell if it is maintained. The MIT license on the libraries also makes it suitable for use in most corporate scenarios as well. – Mike Atlas Jul 27 '10 at 22:46
  • So why did I get a -1? Because you liked another answer better? – Marc Jul 28 '10 at 02:07
  • I guess it doesn't deserve a downvote. If you like, I'll undo it if you make an edit to the post. – Mike Atlas Jul 28 '10 at 17:19
  • 1
    @Mike, if you don't think it answers the question, leave the downvote; I don't care about the rep MMORPG going on. But my opinion is that it solves the problem just fine. But at the very least, leave a comment with why you feel it doesn't solve the problem as stated. The caveat about it being LINQ to Objects is both noted on the page referenced as well as in your original comment. – Marc Jul 28 '10 at 18:18
2

Taken from http://codebeat.wordpress.com/2008/06/23/using-linq-in-net-30/:

  1. First, configure the target framework of the projects using Linq to .NET 3.0. The .NET 3.5 references will be removed.
  2. Then, copy System.Data.Linq.dll and System.Core.dll in the solution, wherever you prefer (in my case, the root folder).
  3. Add them as references in all the corresponding projects. Visual Studio will warn about the assemblies need a later version of the framework. Press Yes.
  4. Set the SpecificVersion property of the references to true. This will prevent compiling errors.

I tried this, and it worked, but beware of Mike Atlas's caution about the legal ramifications of deploying these 2 files.

Patrick McDonald
  • 64,141
  • 14
  • 108
  • 120
  • This raises legal problems with redistributing Microsoft's libraries, actually. Be careful doing this. – Mike Atlas Jul 27 '10 at 22:47
  • This one actually does not work for me. Visual Studio removes System.Core and System.Data.Linq dlls after I change the target framework from 3.5 to 3.0 – Tushar S Jul 28 '10 at 13:56
  • @Silver Gun, did you try adding the references back in after changing to 3.0? – Patrick McDonald Jul 29 '10 at 15:59
  • @Patrick McDonald - Yes but Visual Studio grays out DLLs from incompatible or newer version frameworks. – Tushar S Aug 03 '10 at 19:23
  • Since you've already accepted another answer, I'm not sure why you're still looking at this one. However, it looks like you omitted step 2 above, you need to copy the 2 dlls to your project/solution folder and add them as references from the Browse tab on the Add References dialog, you can't add them from the .NET tab. – Patrick McDonald Aug 05 '10 at 09:33
  • Hi Patrick. Will try that. I accepted the Mono solution, but I'd like something easier without a new installation. Yours is that. =) – Tushar S Aug 05 '10 at 23:53