Disponible uniquement sur Etudier
  • Pages : 8 (1963 mots )
  • Téléchargement(s) : 0
  • Publié le : 5 avril 2011
Lire le document complet
Aperçu du document
Visual LINQ Query Builder
Visual LINQ Query Builder is a Visual Studio 2008 designer that helps you building Linq to Sql queries visually. It is functionally the same experience you had using the Microsoft Access query builder for example but in the Linq domain. The entire UI of this add-in is using Windows Presentation Foundation. The goal of this tool is to help you getting morefamiliar with the Linq syntax.

It's also a project that could help you to see how to start a Visual Studio 2008 add-in using Windows Presentation Foundation.
Using the query bag and the query designer
Using the query bag
The query bag is the main interface of the query designer. It enables you to manage a list of queries in your project. From the query bag, you can do the following:
*Create a new query.
Click the Create new query button to go to the query designer and create the query.
* Edit a query.
Click the Edit query button to go to the query designer and edit the query.
* Delete a query.
* Group queries by type, the two types being VLinq-generated queries and custom-written queries. See "Custom queries" below.
* Select a query.
The selected query isused for Edit, Delete, and Preview actions. You can also edit the selected query's properties, including the name and the description, in the Properties window.
* Preview a query.
First you have to expand the Preview toolbar by clicking the Preview button. The preview pane appears at the bottom of the designer. You can then click the Run button. The designer runs the query according to theprovider configuration. (See "Preview and test requirements" below.) Now the preview pane provides three tabs:
* Results. The result of the query displayed in a data grid.
* SQL. The generated SQL string.
* Generated code. The generated code (C# and Visual Basic).
* Run testing.
First you have to expand the Testing toolbar by clicking the Testing button. A Test column appears in thelist of queries. You can use this column to select or clear the selection of each query for testing. The toolbar offers Select All and Unselect All shortcuts. You can then run the test from the Testing toolbar. This will run all the selected queries against the database. The goal is not to preview the results, but to be sure that the queries are running correctly. Each test result (Ok or Failed)appears in the Test column. "Failed" appears in red and you can click it to see the error details.

Preview and test requirements
To enable the running of previews or tests, you will have to configure the query bag to do this. Except for running previews and tests, the designer is not related to any specific database. The designer only generates LINQ to SQL code. For previews and tests, youhave to configure the query bag’s connection string. You can find the connection string, in either query bag or query designer mode, in the Properties window. A dialog box helps you to either provide a connection string manually, by using a text box, or select an existing Visual Studio connection string like you can do in Server Explorer.

Some queries have parameters. The parameters of thecurrently selected query dynamically appear in the Properties window. You just have to provide your test values. All of these parameters are saved in the VLinq file, so you can retrieve them at any time when you go back to preview mode. These parameters are also used when you run tests; they are considered as your test values.
Custom queries
You can manage all VLinq-generated queries in the query bag.Having all your project queries in the same place helps you to organize them. Because you might write some queries manually, after you become more familiar with LINQ or when you write queries that are too complex for VLinq to generate, the query bag enables you to display and test them in the same environment.
VLinq generates a static class that is partial. (See the Class name attribute in the...