TKIT_dev

Filtering collections by multiple field values in LLBLGen Pro ORM

October 22, 2017

Sometimes we need to fetch a very specific subset of records from the database. For example when we already have a list of specific Id’s of records that we need to fetch. That’s what this post will cover.

To accomplish this kind of filtering with LLBLGen we need to use the FieldCompareRangePredicate. It’s usage is very similar to the FieldLikePredicate from the previous post of the series.

// Fetch all products that match product id's from the array
var ids = new[] { 1, 5, 8, 9 };
var products = new EntityCollection<ProductEntity>();

var rangePredicate = new FieldCompareRangePredicate(ProductFields.ProductId, null, ids);
var filter = new PredicateExpression(rangePredicate);

using(var adapter = new DataAccessAdapter())
{
    adapter.FetchEntityCollection(products, filter);
}

That’s it. If you have any questions, please leave them bellow.


Written by Tihomir Kit, a senior software engineer @Dovetail.
🖖 Stay curious. @GitHub