Linq OrderBy breaks with navigation property being null

前端 未结 2 1535
春和景丽
春和景丽 2021-02-04 01:02

Working with four tables.

Users -> has basic user info including a userid and a departmentid (int)
Groups -> basic group info including a groupid
GroupsMembers -

2条回答
  •  执笔经年
    2021-02-04 01:36

    How about using the coalesce operator?

    userQuery = userQuery.OrderBy(u => u.Department.Name ?? string.Empty);
    

提交回复
热议问题