0

I created an Entity Framework app using NetCore 2.2. It's just a simple app that has models and controllers that were scaffolded from my database.

In my database, if I run this query, I will get the expected 4 rows of data back.

select * from BookSeries where mainBookID = 'akfj36hf'

In my controller, I'm trying to mimic the SQL above, with this code:

[HttpGet("BookSeriesByMain/{id}")]
public async Task<List<BookSeries>> GetBookSeries(string id)
{
    return await _context.BookSeries.Where(n => n.MainBookId == id).ToListAsync();

}

When I hit the controller URL, with the same id of 'akfj36hf', it is returning EVERY row in the database for that table(BookSeries). Not just the expected 4 rows.

Here is my model:

public partial class BookSeries
{
    public string BookLinkId { get; set; }
    public string MainBookId { get; set; }
    public string ChildBookId { get; set; }
    public int? OrderId { get; set; }

    public virtual BookList MainBook { get; set; }
}

I'm kind of at a loss as to what I did wrong.

Does anyone see anything that I messed up?

THanks!

SkyeBoniwell
  • 6,345
  • 12
  • 81
  • 185
  • 1
    Can you confirm that this code is hit by setting a breakpoint? It seems that the action [HttpGet("BookSeriesByMain")] is executed instead. –  Jul 30 '19 at 22:11
  • Yes, it's hitting that controller and the proper ID is getting passed into {id}. – SkyeBoniwell Jul 31 '19 at 14:01
  • I wonder how you configured the table. What is the key of the table? Can you show the DbContext? And what does BookList look like? –  Jul 31 '19 at 20:37
  • You should capture the SQL query, to see what is going on: https://stackoverflow.com/questions/37527783/get-sql-code-from-an-ef-core-query – hujtomi Aug 13 '19 at 13:45

0 Answers0