Find a mistake in the LINQ request.



  • There's an O.D., it has tables:

    Checkout (Checkout key, ReaderID, BookID LibrarianID, Checkout Date, Return Date)
    

    Authors (AuthorID, FirstName, MiddleName, LastName)

    Books (BookID, Title, AuthorID, GenreID, ImprintID, Quantity).

    It must have been understood that the Books table contained information on the books, the Authors Info table, and the Checkout Info on the issuance of books.

    In my request, I wanted to get some sort of extradition rating, which books were most published and to sort out the receipt table on the delivery ring.

    using (var db = new LibraryContext()) {
    var query = (from che in db.Checkout
    group che by che.BookID into g
    from che in g
    from boo in db.Books where boo.BookID == che.BookID
    from aut in db.Authors where aut.AuthorID == boo.AuthorID
    select new {
    FirstName = aut.FirstName,
    MiddleName = aut.MiddleName,
    LastName = aut.LastName,
    Title = boo.Title,
    Count = g.Count(),
    }
    ).OrderBy(p => p.Count).Distinct().ToList();

            this.dataGridView.DataSource = query;
            this.dataGridView.Refresh();
        }
    

    Ultimately, the data obtained will be added to the new table: the author ' s FIO, the title of the book, the number of deliveries.

    Everything worked out except for the sorting. It's not possible to quantify at the end. Help:



  • It's not possible to quantify at the end.

    Distinct should be called to OrderBy.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2