How to get a filtered list from an existing list

Viewed 63

This project is a .NET Core 6 Blazor PWA hosted and using the shared-"Heading"-model, server-repository, server-controller and client-service tasks.

On the client-side, this filtering does NOT work and am very confused why it does not work.

The Heading model class contains fields for

int UID_HEADING
int UID_CUSTOMER
string TXT_NAME
boolean BOOL_IS_ACTIVE 
int INT_SORT_ORDER 

The IEnumerable Heading _AllHeadings list contains 5 records.

In the UI, there is a dropdown showing the CUSTOMERS (1 to 23).

I need to filter the _AllHeadings based on the customer's pUID_CUSTOMER and I tried this:

_FilteredHeadings = _AllHeadings
    .Where(c => (c.UID_CUSTOMER == pUID_CUSTOMER) 
             && (c.BOOL_IS_ACTIVE == bIsActive))
    .OrderBy(e => e.INT_SORT_ORDER)
    .ToList();

However, the _FilteredHeadings only contains ONE record, even though there should be a subset of the complete list of _AllHeadings.

I am very confused as to why this lambda code does not do what I think it should do.

I am not much experienced in Linq and lambda code.

BTW -- if I change the development-code to

_FilteredHeadings = _AllHeadings;

Then all of the records appear -- for all customers.

Your answers, comments and questions are welcome.

Thanks.

0 Answers
Related