The Query Explorer is a simple application, and utility, which you can use to learn LINQ.
If you're new to LINQ, or not familiar with some of its more arcane syntax, a simple utility showing sample queries for many LINQ operators, and the query results, can be a handy tool.
The Query Explorer is an adaptation of a tool first distributed by Microsoft with the Entity Framework v1 called Entity Framework Query Samples. These samples were in turn based on the MSDN "101 LINQ Samples".
The DevForce version uses the same Microsoft sample database (NorthwindEF) and a "DevForce-enabled" model. The primary difference is that the DevForce samples use an EntityManager, and also illustrate other DevForce features such as control over query execution and offline support.
In DevForce a LINQ query may be executed either synchronously or asynchronously, although only synchronous query execution is shown in the utility.
Using the tool you can select a query and a QueryStrategy and then run the query to see the results. It also allows you to start a TraceViewer to see tracing activity while queries run.
This is not a sample for how to build a WinForms application with DevForce.
Here are a few things to try:
Note that the default QueryStrategy is DataSource Only, meaning that any selected query will be run against the backend datasource. But you can change the strategy to any of the others supported by DevForce to explore the action of the other QueryStrategies. (You can learn more about DevForce QueryStrategies in the Developers Guide and in the Data Retrieval tutorials.)
Some queries that returned results with the QueryStrategy of DataSourceOnly may not return results with the QueryStrategy of CacheOnly, even after having been run the first way. That occurs with some queries that must examine objects of a type different than the return type. See the topic of “Query Inversion” in the Developers Guide for details.
C# | var query = context.Customers .Include("Orders") .Include("Orders.OrderDetails") .Include("Orders.OrderDetails.Product") .Include("Orders.OrderDetails.Product.Supplier"); query.QueryStrategy = QueryStrategy.DataSourceOnly; query.ToList(); |
VB | Dim query = context.Customers _ .Include("Orders") _ .Include("Orders.OrderDetails") _ .Include("Orders.OrderDetails.Product") _ .Include("Orders.OrderDetails.Product.Supplier") query.QueryStrategy = QueryStrategy.DataSourceOnly query.ToList() |
This query loads into the cache all Customers from the data source, along with their associated Orders; the OrderDetails associated with those Orders; the Products referenced in the OrderDetails; and the Suppliers for the Products. Of course, in a real enterprise app, that would be a great deal of data to bring down to the client; but just adding a .Where() on the context.Customers part of the query to limit yourself to one or a few Customers would make it a very realistic operation to perform. Having loaded all the data needed for the Customer or Customers on which you were working, your data maintenance operations would zip along at local bus speed!
This solution uses the NorthwindEF database originally distributed by Microsoft. The NorthwindEF database is provided in a zip file in the Data folder of this learning unit. Unzip the component files and attach them to your instance of SQL Server. Be sure to check the connectionStrings in the app.config file too.