InterStellaR
InterStellaR

Reputation: 1

Any alternative for this 'Where' LINQ query

i have this linq query. I need to look for any good alternative if possible for this higlighted lambda expression inside Where condition. I was thinking to use coalesce condition ( ?? ) but couldnt make a query.

.Where(p => p.Property== null ? true : p.Property.SubPropertyList.Contains(Item))

So, I want to get those items from list which has a property null or if not null then satisfies a condition ( Contains() )

Upvotes: 0

Views: 247

Answers (2)

Smitha Kalluz
Smitha Kalluz

Reputation: 337

 var result = list
            .Where(p =>p.Property == null || p.Property?.SubPropertyList.Contains(1) == true);

Upvotes: 0

Ygalbel
Ygalbel

Reputation: 5519

You need to create a predicate. A function that will return true of false.

In you case: .Where(***p => p.PalletMission == null || p.PalletMission.Destinations.Contains(currentGtpOrder.GtpStation.Node))

Upvotes: 2

Related Questions