I'm doing my homework - making an web api 2 project with entity framework.
Here is my table layout, with m-2-m relationship between Singer and Genre tables.
My Genre is a table which I Use to get my singers list by alphabet (so Genre table get data from (ID: 1, Name: "A") to (ID: 26, Name: "Z")
Now I want to get all singers start with "H" (id=8)
public IQueryable<Singer> GetByGenre(int id)
{
return db.Singers.Where(s => s.Genres.Any(g => g.ID == id));
}
with this query:
http://localhost:6798/api/Singers/GetByGenre?id=8
But the result's strange - only the first result's show, while others return as "ref" ? I checked by create a "fake" list
var list = db.Singers.Where(s => s.Genres.Any(g => g.ID == id)).ToList();
and put debug on it, and it return correct 3 Singers ?
--
And as you see, I have other table (Song, Playlist, Video) which have a FK point to ID of my Singer , so how can I only return the Singer table's columns only (ID, NAME, IMAGE) without all other relationship data ( Playlists, Songs, Videos ...) ?