I am trying to limit the data returned via a repository using the where clause based on a list of values.
I have a PurchaseOrders entity where I want to return all purchase orders that have an OrderStatus of either “Open” or “Invoiced”.
I am passing in those paramaters as a string array named purchaseOrderParams.orderStatus.
These values will change based on the user selection in the client app.
If I was writing an sql it would look like.
SELECT ALL FROM PurchaseOrders WHERE OrderStaus IN ('Open', 'Invoiced')
Now I understand that I need to convert the string array of purchaseOrderParams.orderStatus to a list
List<string> orderStatusList = new(purchaseOrderParams.OrderStatus);
And I am trying to pass it to the query
var query = context.PurchaseOrders
.Include(x => x.Supplier)
.AsQueryable();
query = query.Where(x => x.OrderStatus!.Contains(orderStatusList));
My where clause appears to be failing.
Argument 1: cannot convert from ‘System.Collections.Generic.List’ to ‘char’
Any ideas?
I have tried to adapt a bunch of different types of examples that include contains and any but I can’t figure it out.
michael is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.