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?
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.