I have an action, which shoeuld return a limited list of store items from a DB, here the code below
[HttpGet]
public IEnumerable<ProductInfo> GetTop(int amount = 5)
{
var mostPopulardProductIds = dbe.SalesOrderDetail.GroupBy(p => p.ProductID)
.OrderByDescending(p => p.Count())
.Take(amount)
.Select(p => p.Key)
.ToList();
var result = dbe.Product
.Where(p => mostPopulardProductIds.Contains(p.ProductID))
.Select(p => new ProductInfo()
{
Id = p.ProductID,
Name = p.Name
}
).ToList();
return result;
}
and here's my ProductInfo class
[DataContract]
public class ProductInfo
{
public int Id { get; set; }
public string Name { get; set; }
//public
}
But when I try to access it via browser, I get list of empty objects, which are looking like the 1st pic
But debugger shows me, that result variable containing normal objects with data


I've tried to return result through Request.CreateResponse method, but this still does not work
Please add DataMember attribute to class properties, change ProductInfo class
[DataContract]
public class ProductInfo
{
[DataMember]
public int Id { get; set; }
[DataMember]
public string Name { get; set; }
}
More about Data Member
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With