Getting LINQ to work in your new or Exisitng non-LINQ setup project
I read in ScottGu's post the other day that LINQ can also be used under Web Access Projects (aka "WAP"). All the 2.0 sites I build I use the WAP setup for, because I'm addicted to the 1.1 way of doing things.
Anyway, if you install LINQ, one of the wins you get is a new set of LINQ templates in your Visual Studio. This is great if you're setting up a new project, not so great if you're trying to integrate LINQ into an existing project.
So here's what I did, and how I fixed it.
I created a sample LINQ project, and took a look at the auto referenced assemblies. Then I went back to my WAP application, and referenced those assemblies. Then I started my LINQ demo code. All worked well. Generating code from sqlmetal.exe, the inserts, compilation, everything was fast and easy. I can't believe how great LINQ is.
So then my next demo is to start some selects, and using the new LINQ syntax. This didn't get me so far. I found out that there is one more hidden step in LINQifying an existing project. You have to make a minor modification to the MSBUILD commands in your project file. Follow these steps ...
- Close your project
- Open your project file in trusty Notepad
- Just before the closing </Project> node at the bottom of the file add this node
<Import Project="$(ProgramFiles)\LINQ Preview\Misc\Linq.targets" />
This little gem was the final step (at least so far [knock on wood]) that I needed to LINQify my existing project, and now all is well.
Hope this helps