I have 3 classes / tables: Car, User and UserVote (which is a bridging table between the other two).
For example:
Car (id / name):
1 / Ford Focus
2 / Honda Civic
3 / Citroen C2
User (id / ignoreUser):
1 / false
2 / true
3 / false
UserVote (UserId / CarId)
1 / 2
1 / 3
2 / 1
3 / 2
I have a method which gets the top x cars based on the number of votes.
public IQueryable<Car> GetTopCars(int count)
{
return context.Car
.Include(car => car.UserVote)
.Where(car => car.UserVote.Count > 0)
.OrderByDescending(car => car.UserVote.Count)
.Take(count);
}
This code only looks at the Cars and UserVote table and doesn't look at the ignoreUser field on User. I am trying to update my Entity Framework code to join to the User table, but I'm not having any success. Ultimately I am looking to get a list of Cars ordered by the number of UserVotes, excluding those with IgnoreUser set to true. In the above example, I would like the method to return IQueryable in the correct order (Honda Civic then Citroen C2).
I think I want to take Cars and then left join this to User inner joined with UserVote? Is this possible with Entity Framework?
This question follows on from the advice given in a comment to a previous question.