public List<CompanyRatingInfo> GetTopCompanies()
{
return objectContext.Companies.OrderBy(c => c.Reviews.Sum(r => r.Rating))
.Select(co => new CompanyRatingInfo()
{
CompanyID = co.CompanyID,
CompanyName = co.Name,
CreateDate = co.CreateDate,
Logo = co.Logo,
Rating = co.Rating ?? 0,
ReviewsCount = (co.Reviews != null ? co.Reviews.Count : 0),
WebSite = co.Website
}).ToList();
}
错误:
无法比较“System.Data.Objects.DataClasses.EntityCollection`1”类型的元素。仅支持原始类型(例如 Int32、String 和 Guid)和实体类型。
我如何ReviewsCount
通过检查 co.Reviews != null 获得?
`Company` has many `Reviews` which has `Rating`