Here's the SQL that I used to prototype the LINQ statement. The GUID's in code are List<GUID>
. I tried for 3 hours and just don't get it. Could some kind sole who can write LINQ in their sleep help me out.
SELECT DISTINCT [id]
,[emailAddress]
,[name]
,[emailRunNumber]
FROM [emailAddress]
join promotionsJoin
on promotionsJoin.EmailAddressId = emailAddress.id
where promotionsJoin.promotionId in ('09464b57-f3d7-41ec-b0b1-cbc5999824bd',
'8bc855b2-2f01-4083-b43a-dab7b7a81ac8') AND emailRunNumber is NULL
(from emailAddress in emailAddresses
join promotion in promotions
on emailAddress.id equals promotion.EmailAddressId
where guidsList.Contains(promotion.promotionId)
&& promotion.emailRunNumber == null
select new {
emailAddress.id,
emailAddress.emailAddress,
promotion.name,
promotion.emailRunNumber
}).Distinct()
The join here will be unnecessary if there's already a relationship between the two tables in your mapping (then promotion
will just be a field off of emailAddress
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With