I have a controller:
public IEnumerable<Food> Get()
{
FoodDiaryContext cs = new FoodDiaryContext();
var foodquery = cs.Foods.OrderByDescending(c => c.Description).ToList();
return foodquery;
}
It should display:
{
id:1
description:food
measure:[]
}
But I am getting an error:
Type 'System.Data.Entity.DynamicProxies.Food_219DB877F13A4776536ADFD2AC86DB1FDBF0E8887DB7E9D658EFE7D9462C3BD5' with data contract name 'Food_219DB877F13A4776536ADFD2AC86DB1FDBF0E8887DB7E9D658EFE7D9462C3BD5:http://schemas.datacontract.org/2004/07/System.Data.Entity.DynamicProxies' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer.
public class Food
{
public Food()
{
Measures = new List<Measure>();
}
public int Id { get; set; }
public string Description { get; set; }
public virtual ICollection<Measure> Measures { get; set; }
}
public class Measure
{
public int Id { get; set; }
public string Description { get; set; }
public double Calories { get; set; }
public double Fats { get; set; }
public double Protein { get; set; }
public double Carbohydrates { get; set; }
public virtual Food Food { get; set; }
}
Can anyone please tell me what I have done wrong?
Thanks