I have some method with linq query. Logic is next, if I pass null for list of role ids, I want all roles to be included in process, but if it has value, I want only those with id in the list. I am receiving exeption.
public static List<NameEmail> GetNameEmailPairs(Guid guid, List<int> recipientRoles)
{
using (var tc = TransactionContext())
{
var dc = tc.DataContext;
var nameEmailPairs = (
from email in dc.Emails
join logon in dc.Logons on email.GUID equals logon.GUID
join eLogon in dc.ELogons on logon.UID equals eLogon.LogonGUID
join role in dc.Roles on entityLogon.PrimaryPermissionRoleID equals role.RoleID
where
(recipientRoles == null || recipientRoles.Contains(role.RoleID))
select new NameEmail
{
Email = email.EmailAddress,
FullName = GetName(logon.GUID)
}
)
.ToList();
return nameEmailPairs;
}
}
This part is breaking (recipientRoles == null || recipientRoles.Contains(role.RoleID)). Can you please help me with this, what should I do?