locked
LINQ query joining between Contact and ListMember RRS feed

  • Question

  • Hi,

    I want to be able to perform a LINQ query that returns all contacts on a marketing list, I have the following query, but I get the error message 'The type of one of the expressions in the join clause is incorrect.  Type inference failed in the call to 'Join'. 

    Which is referring to the join between c.ContactId which is a Guid and l.EntityId which is an EntyReference.

    Can anybody help me resolve this?

    var contacts = (from c in orgContext.ContactSet
    join l in orgContext.ListMemberSet on c.ContactId equals l.EntityId                          
    where (c.EMailAddress1 == "" && c.EMailAddress2 != "")
    && l.ListMemberId = listid
    select new Contact
    {
    ContactId = c.ContactId,
    EMailAddress1 = c.EMailAddress1,
    EMailAddress2 = c.EMailAddress2
    });

    Thanks in advance,

    Phil

    Thursday, December 3, 2015 5:41 PM

All replies

  • Hello,

    Try to change code l.EntityId to l.EntityId.Id to have something like:

    var contacts = (from c in orgContext.ContactSet
    join l in orgContext.ListMemberSet on c.ContactId equals l.EntityId.Id                          
    where (c.EMailAddress1 == "" && c.EMailAddress2 != "")
    && l.ListId.Id == listid
    select new Contact
    {
    ContactId = c.ContactId,
    EMailAddress1 = c.EMailAddress1,
    EMailAddress2 = c.EMailAddress2
    }); 


    Dynamics CRM MVP
    My blog

    Thursday, December 3, 2015 6:00 PM
    Moderator