Book Image

Building Interactive Queries with LINQPad

By : Sébastien Finot
Book Image

Building Interactive Queries with LINQPad

By: Sébastien Finot

Overview of this book

<p>If you need to interact with databases, XML, in-memory collections, or remote services, LINQ can make your life simpler. The best way to discover LINQ is with the help of LINQPad, a free IDE whose first goal is to make sure that writing and interacting with your LINQ query is fun and easy. More generally, LINQPad is a C#/VB/F# scratchpad that instantly executes any expression, statement block, or program with rich output formatting and a wealth of features.</p> <p>With Building Interactive Queries with LINQPad, you will quickly learn everything you need to know to start using LINQ. To accelerate your learning curve, you will discover how to use LINQPad and its features to test your queries interactively and experiment with all the options offered by LINQ.</p> <p>In all probability, you already know C#, but have you had a chance to try out LINQ? Building Interactive Queries with LINQPad will introduce you to everything LINQ can offer and will let you interact with every example in LINQPad, LINQ’s best companion.</p> <p>You will learn how to build and experiment with interactive queries with this practical guide illustrated with short and detailed code samples. You will also get acquainted with other cool applications of LINQpad such as testing, code snippet generation, and so on, along with a broad approach to LINQ (to object, to SQL, to XML, and so on).</p>
Table of Contents (14 chapters)

Preface

Language Integrated Query (LINQ) is a Microsoft .NET Framework component that extends the language to provide a unified way to query collections and sequences. Those collections can either be local items or data in a remote database. LINQPad is a free IDE that allows you to create programs and to query databases. As its name suggests, LINQPad's main purpose is to write and run LINQ queries, but it can also execute C# or VB Scripts directly from its editor. Also, LINQPad is the perfect companion to learn LINQ!

What this book covers

Chapter 1, Discovering LINQPad, will introduce you to LINQPad, how to install it, how to configure it, and how to use it.

Chapter 2, Coding in LINQPad, will teach you how to use LINQPad as a practical tool to run quick tests and debug snippets of code.

Chapter 3, Learning LINQ Basics, will be your introduction to LINQ.

Chapter 4, Discovering LINQ Query Operators, will continue with LINQ by focusing on defining LINQ to objects and you will also learn about few LINQ query operators.

Chapter 5, Databases and Relational Data, will talk about the LINQ to SQL driver and more LINQ query operators.

Chapter 6, Using other Data Sources, will introduce you to more LINQ drivers: LINQ to XML, LINQ to Entity, and LINQ to WCF Data Services.

Chapter 7, Advanced LINQPad, will show you some of the more advanced features of LINQPad.

What you need for this book

You will need a computer with the .Net Framework installed, with a minimum version of 4.0. You will of course need LINQPad, but Chapter 1, Discovering LINQPad, will provide directions to download and install it.

The following chapters have specific requirements, but they also include pointers on those said requirements:

  • Chapter 5, Databases and Relational Data, requires a SQL Server database of some kind

  • Chapter 6, Using other Data Sources, expects an Internet connection for LINQ to WCF Data Services

Who this book is for

This book is aimed at C# and .Net developers who wish to learn LINQ programming and test the easy way using LINQPad. No prior knowledge of LINQ or LINQPad is expected. A basic knowledge of SQL and XML is required for some chapters

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "We can use OrderBy() to sort a collection on a specific member of the object."

A block of code is set as follows:

void Main()
{
   var deck = CreateDeck();
   var randomCount = random.Next(52);
   var finalDeck = deck.Take(randomCount)
                       .Where (card => card.Suit == "Hearts")
                       .Skip(2)
                       .Take(5)
                       .OrderBy (card => card.FaceValue);
   // Display the result
   finalDeck.Dump();
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

void Main()
{
   var deck = CreateDeck();
   var randomCount = random.Next(52);
   var finalDeck = deck.Take(randomCount)
                       .Where (card => card.Suit == "Hearts")
                       .Skip(2)
                       .Take(5)
                       .OrderBy (card => card.FaceValue);
   // Display the result
   finalDeck.Dump();
}

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "click on the Set as default for new queries button".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title through the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website, or added to any list of existing errata, under the Errata section of that title.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.