tags:

views:

50

answers:

1

I need to provide a null where clause that has no effect.

Currently I have:

f=>{f!=null;}

However that doesn't really look right. If I were to Select clients, I use

.Select(clients => clients)

With my filter I also get a warning about not all code paths returning a result.

+4  A: 

Just return true:

foo.Where(f => true)

Your lambda expression doesn't work for three reasons:

  • You're trying to use f != null as a statement, which it isn't.
  • You don't have a return value.
  • It would reject null values.

The first two can be fixed by removing the braces:

foo.Where(f => f != null)

The last point means it's not really a no-op filter, which is what I guess you meant by "identity filter". Whether it's what you really want or not though, I can't say.

Jon Skeet
Jon got the props here because no op was the phrase I was looking for, but coming from a maths background, identity sits in my brain. I removed the braces you are right there, but the simple return true is what I was looking for.
DavidA