I have next entities:
class Topic
{
public virtual int Id {get; private set;}
public virtual ICollection<Vote> Votes {get; private set; }
}
class Vote
{
public virtual Topic Topic {get; private set;}
public virtual VoteType VotedTo {get; private set;} // enum VotedUp, VotedDown
}
I need to load from the db the next info - all topics (IDs, actually Names, but in this demo case it does not matter) and two more fields CountOfVotedUp, CountOfVotedDown (aggregates). So as I understand in SQL world we need joins, group by, case and count.
Is it posible to get this info with LINQ with less operations with db? I mean N+1, additional selects, connections etc.
All that I tried - is to use NH's LINQ, but it's Query aggregates only on Topic.Id and I could not count any of Votes collection.