this may be a very basic question but I haven’t used Linq much so do need help.
I want to retrieve a list of records based on the related record count.
for example:
I have contact entity which has 1:N relationship with a ‘Role’ entity. I want to select contacts that have
- No related roles
- only 1 related role
How do I write this using Linq
from contact in context.ContactSet
where <contact.Roles has no records> -- ??
select contact;
Please help.
You can check by using
Count() <= 1Linq style:
Method style: