Using Linq in .NET 3.0

23 06 2008

Yesterday I faced an issue: I needed to host an .NET 3.5 application in a .NET 3.0 web server, because the .NET 3.5 web server wasn’t available at time. The application was built using Linq to Sql instead of “traditional” CRUD classes. So I had no choice, but make the app run.

Well, a workaround is to make a local copy of the referenced assemblies; in my case, System.Data.Linq.dll and System.Core.dll.

  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.
  5. Compile.
  6. Run the app!

Download Example Code Using Sql Server Express

Download Example Code Using Just Linq


Actions

Information

3 responses

20 04 2009
Business Software Dorset

Although I get your samples to work (which are ASPX web apps), I have not been able to apply the same method to a Windows Forms application… Could you say whether you think I should or should not be able to use this same approach for a Windows Forms app targeting .net 3.0 ?

20 04 2009
Business Software Bournemouth

Hey, I figured it out, how you do it with Windows Forms apps.

Open the project file with a text editor, and change the

3.5 tag to
3.0

I’m finding it slightly amusing that that is all you have to do to get it to work, but it seems to be so… just need to test my app running against a real 3.0 framework (not just the version simulated by VS2008).

20 04 2009
Business Software Bournemouth

My last post got mangled by the submit process it should have said:

Change the RequiredTargetFramework tag.

Ie.

RequiredTargetFramework>3.53.0<RequiredTargetFramework

Leave a comment