[Solved] How to correctly add Func to Linq?


Reducing the code to its basic form, your first snippet is of the form

list.Where(p => NameContainsPassword(p) || HasEncryptedConfigurationItemAttribute(p))

where I inlined your IsNeverSerializedProperty function.

The second function is of the form

list
  .Where(p => NameContainsPassword(p))
  .Where(p => HasEncryptedConfigurationItemAttribute(p))

which first filters all items for which NameContainsPassword(p) holds and then from that filters all items for which HasEncryptedConfigurationItemAttribute holds, hence this is equivalent to

list.Where(p => NameContainsPassword(p) && HasEncryptedConfigurationItemAttribute(p))

Note that the logical operator is different (|| vs &&).

solved How to correctly add Func to Linq?