2011-12-29 5 views
0

У меня есть этот запрос LINQ, и мне нужно сделать второй присоединиться к нему:Добавление второго Регистрация с помощью LINQ

var linqQuery = (from r in gServiceContext.CreateQuery("opportunity") 
    join c in gServiceContext.CreateQuery("contact") on ((EntityReference)r["new_contact"]).Id equals c["contactid"] into opp 
    from o in opp.DefaultIfEmpty() 
    where ((EntityReference)r["new_channelpartner"]).Id.Equals(lProfileProperty.PropertyValue) && ((OptionSetValue)r["new_leadstatus"]).Equals("100000002") 
    select new 

Но мне нужно также присоединиться это:

from r in gServiceContext.CreateQuery("annotation") 
    join c in gServiceContext.CreateQuery("opportunity") on ((EntityReference)r["objectid"]).Id equals c["opportunityid"] 

К сожалению, я «Конечно, это легко. Однако я сосать в LINQ. Любая помощь будет большой.

Спасибо!

ответ

1

Это не совсем понятно, что вы имеете в виду, но я предлагаю вам хочет:

var linqQuery = from r in gServiceContext.CreateQuery("opportunity") 
       where ... 
       join c in gServiceContext.CreateQuery("contact") 
        on ((EntityReference)r["new_contact"]).Id 
        equals c["contactid"] into opp 
       from o in opp.DefaultIfEmpty() 
       join r in gServiceContext.CreateQuery("annotation") 
        on c["opportunityid"] 
        equals ((EntityReference)r["objectid"]).Id 
       select new... 

Это не понятно, почему вы должны бросить в EntityReference везде и поле доступа через их имена как строки, кстати. Вы уверены, что не можете использовать что-то вроде:

var linqQuery = from opportunity in gServiceContext.Opportunities 
       where opportunity.ChannelPartner.Id == targetChannelPartner 
        && opportunity.NewLeadStatus == 100000002 
       join contact in gServiceContext.Contacts 
        on opportunity.Id equals contact.Id into contacts 
       from contactOrNull in contacts.DefaultIfEmpty() 
       join annotation in gServiceContext.Annotations 
        on annotation.ObjectId equals opportunity.OpportunityId 
       select ...; 
Смежные вопросы