Sdílet prostřednictvím


LINQ Samples

These Visual Basic and C# samples demonstrate LINQ technologies.

To access samples from Visual Studio

  • On the Help menu, click Samples.

    By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.

More current versions of these samples, together with other samples, may be available on the MSDN Code Gallery Web sites for Visual Basic or C#.

Security noteSecurity Note

Microsoft provides the included samples "AS IS" with no warranties. The code in the samples is provided just to illustrate concepts. The provided code may not meet security requirements for any specific environment. We recommend that you add security and error-handling code to your projects to make them as secure and robust as you deem appropriate.

Visual Basic Samples

C# Samples

Connecting to LINQ Sample Databases

The default connection string for the samples should work without modification if you have SQL Server Express installed on your development computer.

On some SQL Server Express installations, you may not have the rights to start a user instance. If you get an error message to that effect, remove the clause ";user instance = true" from the connection string.

Be sure that the copies of the Northwind database that you are accessing are not marked read only. If necessary, browse to the copy of NORTHWIND.MDF that you are trying to access, right-click the file, and then click Properties. Clear the Read-only attribute.

On some slow computers, or when you are using a Virtual PC, users have reported that some database applications give errors the first time that they run. Try to run the sample two or three times.

The customized copies of the Northwind database included with the samples ship without an LDF (log) file. This is intentional so that the LDF and MDF files do not get out of sync. When you run a sample that uses the database, or attach to the database from Server Explorer inside Visual Studio, the LDF file will be created automatically. You may have trouble connecting to the MDF file if you are using the SQL Server Management Studio without first creating a log file.

Samples

Visual Basic

Sample

Description

Sample Queries

Start here if you are new to LINQ. Provides a wide range of examples of query operations for LINQ to Objects, LINQ to SQL, LINQ to XML, and LINQ to DataSet.

Dynamic Query Sample

Illustrates how to create LINQ queries at run time.

Expression Tree Visualizer Sample

Provides a working implementation of a visualizer that can be run inside the Visual Studio debugger to view the contents of an expression tree.

LINQ to Northwind Sample

Provides examples of using LINQ to SQL to query a database.

LINQ to XML Data Binding Sample

Demonstrates LINQ to XML data binding in Windows Presentation Foundation (WPF).

Object Dumper Sample

A library that you can add to your solution to output the results of LINQ queries.

Reflector Sample

Generates an HTML document that outlines the public API for a particular assembly.

RSS Sample

Acts as a small Web server that aggregates several RSS feeds and displays them in a browser.

Simple Lambdas Sample

Provides examples of simple lambda expressions used outside of queries.

Windows Forms Data Binding Sample

Demonstrates how to use LINQ in Windows Forms data-binding scenarios.

Introduction to LINQ to XML Sample

Demonstrates important concepts about LINQ to XML.

XQuery Sample

Shows how to use LINQ to XML to solve the use cases in the XQuery standard.

C#

Sample

Description

Sample Queries

Provides examples of query operations for LINQ to Objects, LINQ to SQL, LINQ to XML, and LINQ to DataSet.

Data Sample

Designed to support many of the scenarios demonstrated in various LINQ samples.

Northwind Mapping Sample

Generates object-relational mapping files used by some other samples.

Simple LINQ to Objects Sample

Shows how to query an in-memory collection.

Dynamic Query Sample

Illustrates how to create LINQ queries at runtime.

LINQ to Northwind Sample

Provides examples of using LINQ to SQL to query a database.

Web Service LINQ Provider Sample

Demonstrates a custom LINQ provider for the TerraServer-USA Web service and a sample client application that uses the custom LINQ provider to query the Web service for geographical data.

LINQ Query Visualizer Sample

A small application that you can run in debug mode in Visual Studio to visualize database queries.

Object Dumper Sample

A library that you can add to your solution to output the results of LINQ queries for testing.

Paste XML as LINQ Sample

Demonstrates a Visual Studio add-in that automatically converts valid XML to the corresponding LINQ to XML statements. (Express versions of Visual Studio do not support add-ins.)

Reflector Sample

Generates an HTML document that outlines the public API for a given assembly.

RSS Sample

Acts as a small Web server that aggregates several RSS feeds.

Simple Lambdas Sample

Provides examples of simple lambda expressions.

Windows Forms Data Binding Sample

Demonstrates how to use LINQ in Windows Forms data-binding scenarios.

Introduction to LINQ to XML Sample

Demonstrates key concepts about LINQ to XML.

XQuery Sample

Shows how to use LINQ to XML to solve the use cases in the XQuery standard.

LINQ to XML Databinding Sample

Demonstrates the LINQ to XML data binding to Windows Presentation Foundation (WPF) feature.

See Also

Other Resources

LINQ (Language-Integrated Query)