我有两个N:N实体 - 彼此相关。举个例子,我会告诉你我的意思:
我最近刚开始使用LINQ,所以也许你们可以帮我解决这个问题。以下我试过,我给了我一个“ AttributeFrom和AttributeTo必须要么指定,要么都是ommited。你不能只传递一个或另一个.AttributeFrom:,AttributeTo:ave_trainerid ” - 错误:
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。如果你可以帮助我,请提前预约!
答案 0 :(得分:1)
来自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);
}
答案 1 :(得分:1)
现在看起来有点倒退(假设我正确解析它)。
你通常做的是先把你的'起始物'放在首位,然后通过映射来找到你想要的那些。我没有任何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();