Skip to main content
Submitted by Xenoveritas on
Topics

The "using System.Linq;" will let the IEnumerable extension methods show up. It has nothing to do with databases.

Without it, LINQ to Objects would not be very discoverable, as you'd have to add the using directive yourself. Whether it's worth it or not to add all the clutter - that's a legitimate debate.

As for "new projects do not contain an assembly reference to System.Linq" (they shouldn't - System.Linq lives in System.Core.dll), I can't reproduce that one--of course, if I explicitly switch a new project to .NET 3.0/2.0 after the fact, then existing classes will have this message, but adding new classes after that correctly avoids adding the "using System.Linq" directive.

Mon, 12/15/2008 - 17:34 Permalink

The project in question currently says it's targeting .NET 3.5, although I didn't create the original project and it was imported into Visual Studio 2008 from Visual Studio 2005 (I think), so there could be some weird setting. Plus at least one developer is using Visual Studio Express Edition 2008, which could also add issues. (Despite the fact that we have an MSDN subscription and I've personally handed him the DVD containing Visual Studio 2008...)

I created a few additional projects that are essentially small test stubs for various parts of the main application (essentially popping up specific forms to allow playing with the UI without loading the entire thing), and these are also set to use 3.5, and they also have the problem I've described: every single class contains "using System.Linq;" and it always generates the compile error.

However, you're right, System.Linq is included in System.Core, and System.Core is referenced in every single project, so... I dunno what's wrong.

Thu, 12/18/2008 - 17:42 Permalink

"The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)"

Really? That's neat because I never added Linq in the first place! Visual Studio did!

Every single new class contains "using System.Linq" - which is pretty stupid because, amazingly enough, not every class needs to work with databases.

To compound the stupidity, new projects do not contain an assembly reference to System.Linq - which generates this warning.

Stupid Visual Studio. Now to hunt for a way to stop it from trying to use System.Linq in every new class file. (Which, annoyingly enough, includes forms.)