JosephStyons
JosephStyons

Reputation: 58745

Imports and references required to use LINQ

I have never used LINQ before, and I am getting an error in an application that does use it. This is a VB.NET (.NET 2.0) project in Visual Studio 2008.

Here is the offending code:

Dim orderedRows = From r In resultRows Order By r.FIELDNAME Select r

And here is the error (names changed to something generic, but otherwise accurate):

Expression of type '1-dimensional array of 
Company.OurLibrary.FunctionalArea.Library.StoredProcStuff.USP_MYPROC.ResultRow'
is not queryable. Make sure you are not missing an assembly
reference and/or namespace import for the LINQ provider.
C:\project\filename.vb

So I recognize that I need to import LINQ libraries. This link led me to add "Imports System.Linq" to the file, but that is an unresolved reference. Based on the same link, I figured I needed to add a reference to "System.Core" to my project, but it is not listed as an available option when I try to add a reference (nor is it already checked).

I feel sure I'm missing something basic. Can someone point me in the right direction?

TL;DR: What do I need for LINQ to work?

Upvotes: 9

Views: 30935

Answers (1)

Ahmad Mageed
Ahmad Mageed

Reputation: 96507

Update: based on the comments targeting .NET 2.0 and attempting to use System.Linq would result in a compiler error as follows:

Namespace or type specified in the Imports 'System.Linq' doesn't contain any public member or cannot be found.

To change the targeted framework version go to the project's Properties -> Compile -> Advanced Compile Options... set the Target Framework to ".NET Framework 3.5" and recompile.

In case using .NET 3.5 is not feasible then you can use LINQBridge to make use of LINQ to Objects while targeting the .NET 2.0 framework.

Upvotes: 9

Related Questions