views:

80

answers:

3

Hi guys

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

+2  A: 

A coworker used LINQBridge and had success.

Marc
wauw nice tool, will check this out
Nealv
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
So why did I get a -1? Because you liked another answer better?
Marc
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
@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
+1  A: 

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
Interesting, nice find.
Marc
This raises legal problems with redistributing Microsoft's libraries, actually. Be careful doing this.
Mike Atlas
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
Silver Gun
@Silver Gun, did you try adding the references back in after changing to 3.0?
Patrick McDonald
@Patrick McDonald - Yes but Visual Studio grays out DLLs from incompatible or newer version frameworks.
Silver Gun
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
Hi Patrick. Will try that. I accepted the Mono solution, but I'd like something easier without a new installation. Yours is that. =)
Silver Gun
+2  A: 

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
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
This is the best answer in the question so far!
Mike Atlas
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