简体   繁体   English

具有多个联接的Dynamics 365 OrganisationServiceContext Linq查询

[英]Dynamics 365 OrganizationServiceContext Linq Query with multiple Joins

I am running into an issue running most of my queries. 我在运行大多数查询时遇到了问题。 I can generate a link query with a join to only one related entity at a time. 我可以一次生成仅具有一个相关实体的联接的链接查询。 But when I run a LINQ query with multiple joins as in the example below, I get the "Sequence contains no elements" error. 但是,当我使用下面的示例运行具有多个联接的LINQ查询时,出现“序列不包含任何元素”错误。

var query =
(
    from permission in context.CreateQuery<ServiceModel.Types.idoe_permission>()
        join contact in context.CreateQuery<ServiceModel.Types.Contact>()
            on permission.idoe_contact_idoe_permission.Id equals contact.Id
        join corporation in context.CreateQuery<ServiceModel.Types.idoe_corporation>()
            on permission.idoe_idoe_corporation_idoe_permission.Id equals corporation.Id
        join role in context.CreateQuery<ServiceModel.Types.idoe_role>()
            on permission.idoe_idoe_role_idoe_permission.Id equals role.Id
    where contact.idoe_ADB2CID == request.UserId
    select new { Corporation = corporation, Role = role }
).ToList();

I am only able to "join" one entity at a time. 我一次只能“加入”一个实体。 Other examples I have seen allow multiple joins, but I have not been able to get this to work. 我看到的其他示例允许多个联接,但是我无法使其正常工作。

Any suggestions? 有什么建议么?

It looks like you're using the relationship names rather than the lookup field names in the joins. 看起来您正在使用关系名称,而不是联接中的查找字段名称。 Using the lookup field names instead might look something like this: 相反,使用查找字段名称可能看起来像这样:

var query = (from permission in context.CreateQuery<ServiceModel.Types.idoe_permission>()
         join contact in context.CreateQuery<ServiceModel.Types.Contact>() on permission.idoe_contactid.Id equals contact.Id
         join corporation in context.CreateQuery<ServiceModel.Types.idoe_corporation>() on permission.idoe_corporationid.Id equals corporation.Id
         join role in context.CreateQuery<ServiceModel.Types.idoe_role>() on permission.idoe_roleid.Id equals role.Id
         where contact.idoe_ADB2CID == request.UserId
         select new { Corporation = corporation, Role = role }).ToList() ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM