CRM 2011-N:N(多对多)Linq问题[英] CRM 2011 - N:N (Many-To-Many) Linq Issue

本文是小编为大家收集整理的关于CRM 2011-N:N(多对多)Linq问题的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我有两个是n:n-彼此相关的实体.用一个示例,我将向您展示我的意思:

  • 我有一个会话(ave_session),我们可以放置"培训师" (ave_trainer)在每个会话上
  • 我正在尝试获取Al的清单 特定会议的"培训师"
  • 他们在 n:n(关系名称:ave_ave_session_ave_trainer)
  • 我在VS2010和C#=>中工作,我正在尝试通过Linq
  • 获取数据

我最近才从Linq开始,所以也许你们可以帮助我解决这个问题.以下我尝试了以下内容,我给了我一个" 属性,必须既指定或两者都可以.您不能仅通过一个或另一个. :

var formatteurs = (from f in ORGContext.CreateQuery<ave_trainer>()
                   join s in ORGContext.CreateQuery<ave_ave_session_ave_trainer>() on f.Id equals s.ave_trainerid.Value
                   join c in ORGContext.CreateQuery<ave_session>() on s.ave_sessionid.Value equals c.Id
                    where c.Id == item.Id
                    select f).ToList();

item.ID是会话的ID.如果您可以帮助我,请提前提前!

推荐答案

来自 msdn 页面:

// List the contacts in the Softball team marketing list.
System.Console.WriteLine("List all contacts in Softball Team:");

var members = from c in crm.contacts
              join mlm in crm.listmembers on c.contactid equals mlm.entityid
              join ml in crm.lists on mlm.listid equals ml.listid
              where ml.listname == "Softball Team"
              select c;

foreach (var c in members)
{
  System.Console.WriteLine(c.fullname + " " + c.emailaddress1);
}

其他推荐答案

似乎有点倒退,就像您现在写的那样(假设我正确解析它).

您通常要做的就是将您的"起点"放在首位,然后浏览映射以获取所需的映射.我没有2011年CRM的经验,所以希望我不会太多的事情. :)

另外,我不喜欢单字符名称,所以我自由使用更长的名字:)

var formatteurs = (
    // first get the session we're interested in
    from session in ORGContext.CreateQuery<ave_session>()
    where session.Id == item.Id

    // now get the mapping rows that are related to it
    join mapping in ORGContext.CreateQuery<ave_ave_session_ave_trainer>() 
        on session.Id equals s.ave_sessionid.Value

    // now get from the mapping rows to the actual trainers
    join trainer in ORGContext.CreateQuery<ave_trainer>()
        on mapping.ave_trainerid.Value equals trainer.Id

    select trainer
).ToList();

本文地址:https://www.itbaoku.cn/post/1556794.html

问题描述

I have two entities who are N:N - related with each other. With an example I'll show you what I mean :

  • I have a Session (ave_Session) and there we can put "Trainers" (ave_trainer) on each Session
  • I'm tryting to get a list of al the "Trainers" for a particular Session
  • They are related to each other in N:N (relationship name : ave_ave_session_ave_trainer)
  • I work in VS2010 and with C# => I'm trying to get the data through LINQ

I recently just started with LINQ, so maybe you guys can help me out on this one. The following I've tried and i gave me an "AttributeFrom and AttributeTo must be either both specified or both ommited. You can not pass only one or the other. AttributeFrom: , AttributeTo: ave_trainerid"-error :

var formatteurs = (from f in ORGContext.CreateQuery<ave_trainer>()
                   join s in ORGContext.CreateQuery<ave_ave_session_ave_trainer>() on f.Id equals s.ave_trainerid.Value
                   join c in ORGContext.CreateQuery<ave_session>() on s.ave_sessionid.Value equals c.Id
                    where c.Id == item.Id
                    select f).ToList();

The item.id is the Id of the session. Thx in advance if you can help me out!

推荐答案

From the MSDN page:

// List the contacts in the Softball team marketing list.
System.Console.WriteLine("List all contacts in Softball Team:");

var members = from c in crm.contacts
              join mlm in crm.listmembers on c.contactid equals mlm.entityid
              join ml in crm.lists on mlm.listid equals ml.listid
              where ml.listname == "Softball Team"
              select c;

foreach (var c in members)
{
  System.Console.WriteLine(c.fullname + " " + c.emailaddress1);
}

其他推荐答案

It seems a little backwards the way you have it written now (assuming I'm parsing it correctly).

What you'd normally do is put your 'starting thing' first and then go through the mapping to get to the ones you want. I don't have any CRM 2011 experience, so hopefully I didn't mess this up too much. :)

Also, I'm not a fan of single-character names, so I took the liberty of using longer names :)

var formatteurs = (
    // first get the session we're interested in
    from session in ORGContext.CreateQuery<ave_session>()
    where session.Id == item.Id

    // now get the mapping rows that are related to it
    join mapping in ORGContext.CreateQuery<ave_ave_session_ave_trainer>() 
        on session.Id equals s.ave_sessionid.Value

    // now get from the mapping rows to the actual trainers
    join trainer in ORGContext.CreateQuery<ave_trainer>()
        on mapping.ave_trainerid.Value equals trainer.Id

    select trainer
).ToList();