I have an Ids array that I want to pass to the entity infrastructure through a Linq query to return any matches
I wrote Linq queries that can convert identifiers to strings and use the "Contains" operator, for example:
Model
public class Order { public long OrderId { get; set; } public string Name { get; set; } ...} Order[] orders = { new Order { OrderId = 123, Name = "Order1" }, new Order {...},...};
for which I can use something like:
long[] testArray = {123, 456};
and then
var result = orders.Where(i => testArray.ToString().Contains(i.OrderId.ToString()));
but do I really need to continue pouring identifiers into strings? It looks like I can't access the "Contains" if I save them as ints.
Ultimately, I want to be able to use this as part of a query that accesses the Entity Framework and therefore passes the query as part of IQueryable <> to make sure that I don't return data when I want only handfull, for example:
var orders = _repo.Orders().Where(i => orderArray.Contains(i.OrderId));
Thus, any solution would be useful if query parameters (int array) via EF instead of receiving all the data and then checking them in memory.
Hurrah!
source share