views:

48

answers:

3

Hello,

Someone recently said that I can use Linq to SQL in my application even if I am targeting the .net 2 framework. Is that true?

How does that work? How do you setup your references? Any gotchas I need to be concerned about? Is there some special way to set that up?

Thanks.

Seth

A: 

The framework targeting in VS 2008 is based on changing/adding/removing assembly references. .NET 2.0, 3.0, 3.5 and 3.5 SP1 all use the same CLR runtime (version 2.0.50727).

So you can (maybe/probably?) add Linq2Sql without targeting 3.5 however it won't change anything since you would still be required to have 3.5 installed, and then why the hassle of setting up your references?!

veggerby
+1  A: 

Linq to SQL is made up of 2 parts:

1) The changes to the C# language for the new Linq syntax. This is all handled by the compiler so you will need vs2008, but once it's compiled you can still run on .net 2.0.

2) The framework classes that do the database access. You would need to find and reference these (System.Core, System.Data & System.Data.Linq I think) and distribute them manually with your app.

.net 2.0/3.0/3.5 all use the same CLR, so in theory it should all be able to work fine on 2.0 provided you distribute the missing assemblies.

In theory I it should work.

In practise you should definitely try it out first.

There's a blog post here on using Linq on .net 2.0, but it doesn't mention anything about Linq-to-sql.

Note the mention of requiring .net 2.0 SP1 because of an updated system.dll.

Simon P Stevens
A: 

You can, but you need to set System.Core to be a local copy version in your application because it doesn't exist in .NET 2 and it's needed for Linq. You need a minimum of .NET 2, SP1 to do this trick though because there's an update in System.dll that is needed.

It's worth noting that you have to develop on a system with .NET 3 on to do this. The deployed code will still work on .NET2 as long as you follow the steps I outlined above.

Pete OHanlon