I've built a small service using the ASP.NET Web Api. My domain classes looks like this:
public class Drink : IEntity
{
public Drink()
{
Ingridients = new List<Ingredient>();
}
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Ingredient> Ingridients { get; set; }
public string Approach { get; set; }
}
public class Ingredient : IEntity
{
public Ingredient()
{
Drinks = new List<Drink>();
}
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Drink> Drinks { get; set; }
}
My Repository Looks like this:
public IEnumerable<T> GetAll(){return _dbSet;}
And my controller looks like this:
public IEnumerable<Drink> GetAllDrinks()
{
return _unitOfWork.Drinks.GetAll();
}
When I make I request using fiddler the JSON result is the following:
{"Id":15,"Name":"Russian Energy","Ingridients":[],"Approach":"Mix Vodka with Redbull"}
As you can see the Ingridents array is empty. Why is that?