Extension method syntax:
prop = @event.Proposals.Where(p => p.Services.Any(
s => !string.IsNullOrEmpty(s.LongDescription)).ToList();
Or query:
prop = (from p in @event.Proposals
where p.Services.Any(s => !string.IsNullOrEmpty(s.LongDescription))
select p).ToList();
NOTE
The logic in your example may not be what you intended; as it stands, it will only add the item if the first Service
has a non-empty LongDescription
(because the break
is outside the if
, so it will break on the first item regardless of whether or not it fits the condition). The logic above is assuming that the example is wrong and you want to add it if any of them have a non-empty LongDescription
.
If, however, that is what you want, then try this:
prop = @event.Proposals.Where(
p => !string.IsNullOrEmpty(
p.Services.Select(s => s.LongDescription).FirstOrDefault())).ToList();