If i understand correctly,
Customer may or may not have the email (Additional) in emails
table.
Also, Customer have more than one additional emails entry in emails
table. Like below
List<Customer> customers = new List<Customer>
{
new Customer { ClientId = 1, Email = "client1@domain.com", Credits = 2 },
new Customer { ClientId = 2, Email = "client2@domain.com", Credits = 1 },
new Customer { ClientId = 3, Email = "client3@domain.com", Credits = 1 },
};
List<Emails> emails = new List<Emails>
{
new Emails { ClientId = 1, Email = "client1-2@domain.com" },
new Emails { ClientId = 1, Email = "client1-3@domain.com" },
new Emails { ClientId = 2, Email = "client2-1@domain.com" },
};
In that case, Use the below query to get it done,
var result = from c in customers
let _emails = emails.Where(e => c.ClientId == e.ClientId).Select(t => t.Email)
where c.Email == "client3@domain.com" || _emails.Contains("client3@domain.com")
select new
{
Allowed = c.Credits > 0,
MainEmail = c.Email
};
I hope it helps you.