【问题标题】:CRM 2013 Retrieve all teams for a given user using LINQCRM 2013 使用 LINQ 检索给定用户的所有团队
【发布时间】:2014-09-08 01:07:34
【问题描述】:

我正在尝试使用 LINQ 和早期绑定实体检索用户所属的所有团队。我在这里做错了什么。

我将 SystemUser 用户作为参数传递给函数

var teams = (from teamList in crmContext.CreateQuery<Team>() 
             join mapping in crmContext.CreateQuery<TeamMembership>() 
                    on teamList.Id equals mapping.TeamId 
             join users in crmContext.CreateQuery<SystemUser>() 
                    on user.Id equals users.Id 
             select teamList
             ).ToList();

据我了解,我首先返回所有团队,然后加入以获得具有会员资格的团队,最后是与给定用户 ID 匹配的用户的会员资格。

它失败并出现以下错误Sequence contains no matching element。我在从用户中删除了触发团队的解除关联消息中有此内容。

我在这里错过了什么?

编辑:

我也尝试过。

var allteams = (from users in crmContext.CreateQuery<SystemUser>() where users.Id == user.Id join mapping in crmContext.CreateQuery<TeamMembership>() on users.Id equals mapping.SystemUserId join teams in crmContext.CreateQuery<Team>() on mapping.TeamId equals teams.Id select teams).ToList();

但是,我收到了这条消息。

方法'Join'不能跟随方法'Where'或者不是 支持的。尝试根据支持的方法编写查询或调用 调用不支持之前的“AsEnumerable”或“ToList”方法 方法。

我相信这是因为 CRM 2013 的 LINQ 提供程序。

【问题讨论】:

    标签: c# linq dynamics-crm dynamics-crm-2013


    【解决方案1】:

    关于您的第二次尝试,请尝试将 where 子句移到 select 子句之前的末尾:

    var allteams = (from users in crmContext.CreateQuery<SystemUser>() 
                    join mapping in crmContext.CreateQuery<TeamMembership>() 
                        on users.Id equals mapping.SystemUserId 
                    join teams in crmContext.CreateQuery<Team>() 
                        on mapping.TeamId equals teams.Id 
                    where users.Id == user.Id 
                    select teams
                    ).ToList();
    

    【讨论】:

      猜你喜欢
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多