---
title: "Generating a lambda by passing in a property name for use in .Count() with Where condition"  
description: "Generating a lambda by passing in a property name for use in .Count() with Where condition"  
author: "Anonymous User"  
published: 2014-01-29  
updated: 2014-01-29  
canonical: https://www.mindstick.com/forum/1910/generating-a-lambda-by-passing-in-a-property-name-for-use-in-count-with-where-condition  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Generating a lambda by passing in a property name for use in .Count() with Where condition

I'm [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to generate a [lambda expression](https://www.mindstick.com/forum/159550/how-to-implement-an-interface-with-two-abstract-methods-by-a-lambda-expression), by passing in the [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) name to [filter](https://www.mindstick.com/forum/1176/filter-in-a-xml-file-in-c-sharp) on as a [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp), then I need to count the [results](https://yourviews.mindstick.com/story/4497/usage-of-baking-soda-magical-results) where an "Enum" is set to a certain [status](https://www.mindstick.com/articles/157184/check-lic-policy-status-online-by-policy-number)

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](https://www.mindstick.com/forum/159623/how-to-get-an-enum-value-from-a-string-value-in-c-sharp) I want to filter by into the lambda?

## Replies

### Reply by Pravesh Singh

Hi Goti,\

You need to compare the property with a constant value:

```
var lambda = Expression.Lambda<Func<ArtworkPage, bool>>(    Expression.Equal(        Expression.Property(expressionParam, property),        Expression.Constant(yourEnumValue)    ),    experssionParam);    
```


---

Original Source: https://www.mindstick.com/forum/1910/generating-a-lambda-by-passing-in-a-property-name-for-use-in-count-with-where-condition

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
