We have two tables - Tasks and TasksUsers (users assigned to task). Task has EntityCollection called TaskUsers.
This query returns number of tasks per username:
model.TaskCountByAssignee =
(
from t in TaskRepository.List()
from tu in t.TaskUsers
group tu by tu into tug
select new {Count = tug.Count(), UserName = tug.Key.Username}).ToList()
This query returns:
Administrator 11
LukLed 5
I want it to return:
Administrator 11
LukLed 5
null 10
Some of tasks don't have any assignment, but I still want them in my result set. Normally, in SQL, it is achieved by changing join
to left join
. In Linq, outside EF, I could use DefaultIfEmpty(). How can it be done in linq to entities?