Home > DeveloperSection > Forums > Generating a lambda by passing in a property name for use in .Count() with Where condition
Goti Bandu

Total Post:119

Posted on    January-29-2014 11:21 PM

 C# C# 

 1 Reply(s)
 616  View(s)
Rate this:

I'm trying to generate a lambda expression, by passing in the property name to filter on as a string, then I  need to count the results where an "Enum" is set to a certain status

var expressionParam = Expression.Parameter(typeof (ArtworkPage), "page");

var body = Expression.Property(expressionParam, property);

var lambda = Expression.Lambda(body, expressionParam,).Compile();

int approvedList = GetArtworkUploadPages(artwork.Id).Count(lambda);

How do I get the final piece of the puzzle in passing what enum value I want to filter by into the lambda?

Pravesh Singh

Total Post:411

Posted on    January-29-2014 11:45 PM

Hi Goti,

You need to compare the property with a constant value:

var lambda = Expression.Lambda<Func<ArtworkPage, bool>>(


        Expression.Property(expressionParam, property),





Don't want to miss updates? Please click the below button!

Follow MindStick