Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6213011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:37:06+00:00 2026-05-24T06:37:06+00:00

In the below (pasted from LinqPad) my (very silly) query return no results. Why

  • 0

In the below (pasted from LinqPad) my (very silly) query return no results. Why not, what is wrong?
(please someone sort the formatting)

void Main()
{
    var csv =
@"#Books (format: ISBN, Title, Authors, Publisher, Date, Price)
0735621632,CLR via C#,Jeffrey Richter,Microsoft Press,02-22-2006,59.99
0321127420,Patterns Of Enterprise Application Architecture,Martin Fowler,Addison-Wesley, 11-05-2002,54.99
0321200683,Enterprise Integration Patterns,Gregor Hohpe,Addison-Wesley,10-10-2003,54.99
0321125215,Domain-Driven Design,Eric Evans,Addison-Wesley Professional,08-22-2003,54.99
1932394613,Ajax In Action,Dave Crane;Eric Pascarello;Darren James,Manning Publications,10-01-2005,44.95";

  using (var reader = new StringReader(csv) /*new StreamReader("books.csv")*/)
  {
    var books =
      from line in reader.Lines()
      where !line.StartsWith("#")
      let parts = line.Split(',')
      select new { Isbn=parts[0], Title=parts[1], Publisher=parts[3] };

    //books.Dump();

    var query =
    from book in books
    from b in books
    where book.Isbn == b.Isbn
    select new 
    {       
        book.Isbn,
        book.Title
    };

    query.Dump();



    // Warning, the reader should not be disposed while we are likely to enumerate the query!
    // Don't forget that deferred execution happens here
  }
}

}// Temporary hack to enable extension methods

/// <summary>
/// Operators for LINQ to Text Files
/// </summary>
public static class Extensions
{
  public static IEnumerable<String> Lines(this TextReader source)
  {
    String line;

    if (source == null)
      throw new ArgumentNullException("source");

    while ((line = source.ReadLine()) != null)
      yield return line;
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:37:07+00:00Added an answer on May 24, 2026 at 6:37 am

    You attempt to enumerate through the books collection twice in your second query. This would not work as-is however since your Lines() extension method reads through the reader to the end at first. Due to the deferred execution, the second enumeration attempts to read off of the now empty reader leading to no results.

    You need to put the results of the books collection into a list (or other collection) so it’s not trying to access the reader again. In your case, you could just call ToList() on your books collection and it should work from there.

    var books =
       (from line in reader.Lines()
        where !line.StartsWith("#")
        let parts = line.Split(',')
        select new { Isbn = parts[0], Title = parts[1], Publisher = parts[3] })
       .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code pasted below was taken from Javadocs on HttpURLConnection . I get the
I'm stuck on a sql server function, pasted below.. I'm trying to return a
Question: The generated XML file from an .XSD template produces the output pasted below.
Below is what I copy/pasted from the Crash Log sent by the client. I
I have a code file from the boto framework pasted below, all of the
I have a script (pasted below) that pulls in the meta descriptions from a
I have a PHP script (pasted below) which pulls in meta data from a
The code pasted below gets an exception on the line that says... InputStream in
The code pasted below is a simple JSF program, with an idea of having
The code I've pasted below works fine for drawing a line step by step

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.