0
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`
4

1 回答 1

2

It should be co.Reviews.Count(). Count is a method.

于 2012-11-21T19:36:25.197 回答