Get filtered results from Episerver Business Foundation class

Last week I come across a requirement to get Episerver commerce list of customers based on filtered criteria such a get customers based on the validity of a certain field. As we all know Episerver store customer data in Business Foundation class called “Contact”.

In my case, I have to get the list of customers opted-in to receive a newsletter. I already have a custom field in the “Contact” BF class called “Subscribed”. The data type of this field is boolean.

The first step is to create filter criteria of type “FilterElement”

var SubscribedFilter = new FilterElement(StringConstants.CustomFields.Subscribe, FilterElementType.Equal, true);

var filters = new[] { SubscribedFilter };

We can create multiple filters and add them together separated by comma such as

var SECONDFILTER = new FilterElement("Subscribe", FilterElementType.Equal, true);

var filters = new[] { SubscribedFilter, SECONDFILTER };

Next step is to call BusinessManager and get results

var customers = BusinessManager.List("Contact", filters).Cast<CustomerContact>();

The last part “Cast<CustomerContact>()” is optional. You can use it if you want to return strongly typed results.

About the author

Naveed Ul-Haq

I'm Naveed. I am a UK based technical architect. I love working with .NET based CMS, eCommerce solutions, .NET Core, DevOps, and Cloud computing. I am a Certified Episerver CMS developer, MCSD (Microsoft Certified Solution Developer) and MCP in Azure application development. I spend my free time with my family and reading books. You can contact me on [email protected]

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *