How to: Create a LINQ to Entities Project in Visual Studio
The different types of Language-Integrated Query (LINQ) projects require certain imported namespaces (Visual Basic) or using directives (C#) and references. The minimum requirement is a reference to System.Core.dll and System.Data.Entity.dll and a using directive for the System.Linq and System.Data.Objects namespaces. LINQ to Entities also requires a reference to the Entity Data Model (EDM) that will be queried over. The examples in the LINQ to Entities section use the AdventureWorks Sales Model (EDM).
If you are upgrading a project from an earlier version of Visual Studio, you might have to supply these LINQ-related references manually. You might also have to manually set the project to target the .NET Framework version 3.5.
Note
If you are building from a command prompt, you must manually reference the LINQ-related DLLs in drive:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5.
To target the .NET Framework 3.5
In Visual Studio 2008, create a new Visual Basic or C# project. Alternatively, you can open a Visual Basic or C# project that was created in Visual Studio 2005 and convert it to a Visual Studio 2008 project.
On the Project menu, click Properties.
For a C# project, in the Application property page, select .NET Framework 3.5 in the Target Framework box.
For a Visual Basic project, in the Compile property page, click Advanced Compile Options and then select .NET Framework 3.5 in the Target Framework (all configurations) box.
On the Project menu, click Add Reference.
In the Add Reference dialog box, click the .NET tab, select System.Core from the Component Name list, and then click OK.
For a C# project, add a using directive for the System.Linq and System.Data.Objects namespaces to your source code file or project.
For a Visual Basic project, add an Imports directive for the System.Linq and System.Data.Objects namespaces to your source code file or project.
To create and reference the AdventureWorks Sales Model
On the Project menu, click Add new item.
In the Templates pane, select ADO.NET Entity Data Model.
Type AdvWorksModel.edmx in the Name box, and then click Add.
Select Generate from database, and then click Next.
In the Choose Your Data Connection window, either select an existing AdventureWorks connection from the list, or create a new connection to a SQL Server instance that has the AdventureWorks sample database.
Save the entity connection settings in App.Config as AdventureWorksEntities and click Next.
In the Choose Your Database Objects dialog box, clear all objects, expand Tables, and select the following table objects:
Address (Person)
Contact (Person)
Product (Production)
SalesOrderDetail (Sales)
SalesOrderHeader (Sales)
Name the model namespace AdventureWorksModel, and then click Finish.
For a C# project, add a using statement for AdventureWorksEntities to your source file.
For a Visual Basic project, add an Imports statement for AdventureWorksEntities to your source file.