I'm trying to make this query work with EF but it throws an exception:
var c = ac.Communities.OrderBy(o => o.Posts.Count())
.Skip(page*limit)
.Take(limit)
.Select(o => o.ToViewModel()).ToArray();
The ToViewModel()
method from the Community
model looks like this:
public CommunityModel ToViewModel()
{
return new CommunityModel()
{
category = Category.Name,
created = CreationTime,
description = Description,
id = Id,
name = Name,
ownerId = Owner.Id,
postsCount = Posts.Count(),
score = Posts.Sum(o => o.Likes - o.Unlikes),
shortDescription = ShortDescription,
subscribersCount = Subscribers.Count(),
};
}
What am I doing wrong?