我使用 ASP.NET Web Api 构建了一个小型服务。我的域类如下所示:
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; }
}
我的存储库如下所示:
public IEnumerable<T> GetAll(){return _dbSet;}
我的控制器看起来像这样:
public IEnumerable<Drink> GetAllDrinks()
{
return _unitOfWork.Drinks.GetAll();
}
当我使用提琴手提出请求时,JSON结果如下:
{"Id":15,"Name":"Russian Energy","Ingridients":[],"Approach":"Mix Vodka with Redbull"}
如您所见,Ingridents 数组为空。这是为什么?