I am building a gaming website where Games have collection of Categories
public class Game
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<CategoryMain> categoryMain { get; set; }
}
I want to find list of Games by choosing 1 category from the list of categories.
var games= await db.Games.Include(u => u.applicationUser)
.Include(c => c.categoryMain)
.Where(c => c.categoryMain.Id == x) // <-- My Issue Here
.ToListAsync();
Because "categoryMain" is a collection, I cannot access it's properties "Id" to filter games by category.
Previously I had Games have 1 category only, things works fine, but now I want to have the ability for games to have multiple categories, so I really need this.
Thanks