Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does LINQPad reference other classes, e.g. Books in the LINQ in Action samples

I'm using LINQPad to create LINQ queries in an application I'm bulding.

I noticed that in the downloaded LINQ in Action samples, e.g. example 4.04, intellisense shows a class "Books" but I don't see any references or "using" statements in the LINQPad tool, here is the sample:

List<Book> books = new List<Book>() {   new Book { Title="LINQ in Action" },   new Book { Title="LINQ for Fun" },   new Book { Title="Extreme LINQ" } };  var titles =   books     .Where(book => book.Title.Contains("Action"))     .Select(book => book.Title);  titles.Dump(); 

In "LinqBooks.Common, Business Objects, Book.linq" is where the class seems to be defined:

public class Book {   public IEnumerable<Author> Authors {get; set;}   public String Isbn {get; set;}   public String Notes {get; set;}   public Int32 PageCount {get; set;}   public Decimal Price {get; set;}   public DateTime PublicationDate {get; set;}   public Publisher Publisher {get; set;}   public IEnumerable<Review> Reviews {get; set;}   public Subject Subject {get; set;}   public String Summary {get; set;}   public String Title {get; set;}   public String Test {get; set;}    public override String ToString()   {     return Title;   } } 

But how does this work so that I can copy in my classes and use LINQPad to quickly build LINQ statements that I can then copy back into my application?

like image 231
Edward Tanguay Avatar asked Aug 03 '09 12:08

Edward Tanguay


People also ask

How to add References in LINQPad?

Open up LINQPad and go to File -> New Query or Press Ctrl + N. On Query menu, click Reference and Properties or press F4 to add reference.

How does LINQPad work?

LINQPad automatically patches itself by downloading updates into its Application Data folder. It then checks that the new assembly has a valid signature, and if so, forwards to that executable, which then writes itself back to the original file.

Where are LINQPad samples stored?

LINQPad stores queries in a folder named LINQPad Queries by default, located into the user's Documents folder. All queries saved are displayed beneath a tree view node called My Queries. For the purposes of this book, every query written in LINQPad will be saved in a folder named LINQPad Samples.

What is LINQPad used for?

LINQPad is a software utility targeted at . NET Framework and . NET Core development. It is used to interactively query SQL databases (among other data sources such as OData or WCF Data Services) using LINQ, as well as interactively writing C# code without the need for an IDE.


1 Answers

If you right click in the code editor in LINQPad and choose Advanced Query Properties, there are two dialogs: Additional References and Additional Namespace Imports.

1) In Additional References, choose Add then click Browse and navigate to your custom assembly.

2) Then, in Additional Namespace Imports, type the namespaces you want to import from that assembly.

like image 77
Winston Smith Avatar answered Sep 28 '22 08:09

Winston Smith