CRM 2011-N:N(多对多)Linq问题
我有两个实体,它们彼此是N:N相关的。通过一个例子,我将向您展示我的意思: 我有一节课,在那里我们可以放训练员 每节课的ave_培训师 我在试着弄一份所有人的名单 特定课程的培训师 他们在生活中相互关联 N:N关系名称:ave_ave_session_ave_trainer 我在VS2010中工作,使用C=>我试图通过LINQ获取数据 我最近刚开始接触LINQ,所以也许你们可以帮我解决这个问题。我尝试了以下内容,并给了我一个AttributeFrom和AttributeTo必须同时指定或同时指定。你不能只通过其中一个。AttributeFrom:,AttributeTo:ave_trainerid-错误: item.id是会话的id。如果你能帮助我,请提前通知我 从页面:CRM 2011-N:N(多对多)Linq问题,linq,dynamics-crm-2011,crm,Linq,Dynamics Crm 2011,Crm,我有两个实体,它们彼此是N:N相关的。通过一个例子,我将向您展示我的意思: 我有一节课,在那里我们可以放训练员 每节课的ave_培训师 我在试着弄一份所有人的名单 特定课程的培训师 他们在生活中相互关联 N:N关系名称:ave_ave_session_ave_trainer 我在VS2010中工作,使用C=>我试图通过LINQ获取数据 我最近刚开始接触LINQ,所以也许你们可以帮我解决这个问题。我尝试了以下内容,并给了我一个AttributeFrom和AttributeTo必须同时指定或同时指定
假设我正确地解析了它,它看起来有点像你现在写的那样 你通常会做的是把你的“开始的东西”放在第一位,然后通过映射找到你想要的。我没有任何CRM 2011的经验,所以希望我没有把事情搞砸太多 此外,我不喜欢单字符名称,因此我冒昧地使用了更长的名称:
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();
我也发现了。。上述联接基于此。。但我似乎没有找到正确的方法。。。我是否首先需要从关系中执行?或者?不要使用f.id和c.id,尝试使用f.ave_trainerid和c.ave_sessionid。答案是Peter的注释。id不是LINQ查询中Guid字段的可用缩写。请参见以下类似问题/答案:
// 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);
}
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();