In C#, I'm attempting to do multiple extension-method joins, in which the second join is with an enumerable of an anonymous type produced by the first join:
List<Contact> filteredContactList = GetFullContacts()
.Join(GetContactCompanyRoles()
, ct => ct.IdContact
, ctCmpRole => ctCmpRole.IdContact
, (ct, ctCmpRole) => new { Contact = ct, ContactType = ctCmpRole.ContactType })
.Join(GetContactRoles()
, ctf => new { ctf.Contact.IdContact, ctf.ContactType }
, ctRole => new { ctRole.ContactId, ctRole.ContactType }
, (ctf, ctRole) => new { Contact = ctf.Contact, PrimaryInd = ctRole.IsPrimary})
.Select(rec => rec.Contact)
.ToList();
ct and ctf.Contact is of Type Contact.
I am, however, getting the following error when attempting to compile:
The type arguments for method 'System.Linq.Enumerable.Join...' cannot be inferred from the usage. Try specifying the type argument explicitly.
Is there a way to get around this error without having to create an actual class for the anonymous type from the first join? Are there other options that I am not considering?
JoinandGroupJoinI feel is quite messy to write in lambda.