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

查看:185
本文介绍了CRM 2011-N:N(多对多)Linq问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个彼此为N:N的实体.通过示例,我将向您展示我的意思:

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

  • 我有一个会话(ave_Session),我们可以在其中放置培训师" (ave_trainer)在每个会话上
  • 我正在尝试获取所有 特定会话的培训师"
  • 它们在 N:N(关系名称:ave_ave_session_ave_trainer)
  • 我在VS2010中工作,并且使用C#=>我正在尝试通过LINQ获取数据
  • 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

我最近刚开始使用LINQ,所以也许你们可以帮我解决这个问题.我尝试过以下操作,并给了我一个" AttributeFrom和AttributeTo必须同时指定或都省略.您不能只传递一个或另一个.AttributeFrom:,AttributeTo:ave_trainerid "-错误:

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();

item.id是会话的ID.如果您能帮助我,请提前谢谢!

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

推荐答案

您现在编写的方式似乎有些倒退(假设我正确地解析了它).

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

您通常要做的是先放置开始的东西",然后进行映射以找到所需的对象.我没有任何CRM 2011经验,所以希望我不会对此太过混乱. :)

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();

这篇关于CRM 2011-N:N(多对多)Linq问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆