某些代理在组字段中为空。我正在尝试进行 LeftJoin,但收到类似 InnerJoin 的结果(仅限具有非空组的代理)
Agents = new ObservableCollection<dynamic>((await _repository.GetAgentsAsync() ?? new Agent[] { })
.Join(Groups.DefaultIfEmpty(), a => a.Group, g => g.ID, (a, g) =>
new { ID = a.ID, AgentName = a.AgentName, Login = a.Login, AgentID = a.AgentID, IsDel = a.IsDel, Group = g == null ? "Empty" : $"{g.NameGroup} ({g.Num})" }));
问题是什么?
谢谢大家,我找到了答案https://stackoverflow.com/a/21584913/13618303
Groups = new ObservableCollection<Group>(await _repository.GetGroupsAsync() ?? new Group[] { });
Agents = new ObservableCollection<Agent>(await _repository.GetAgentsAsync() ?? new Agent[] { });
AgentsGroups = new ObservableCollection<dynamic>(Agents.GroupJoin(Groups, a => a.Group, g => g.ID, (a, g) => new { Agent = a, Group = g})
.SelectMany(ag => ag.Group.DefaultIfEmpty(), (a,g) => new { Agent = a.Agent, Group = g })
.Select ( ag => new { ID = ag.Agent.ID, AgentName = ag.Agent.AgentName, Login = ag.Agent.Login, AgentID = ag.Agent.AgentID, IsDel = ag.Agent.IsDel, Group = ag.Group == null ? "Empty" : $"{ag.Group.NameGroup} ({ag.Group.Num})" }));