-2

I have a function that takes a parameter of string[]. StoreHierarchy has a property named AreaNbr, which is a int.

public Task<IEnumerable<StoreHierarchy>> GetStoreHierarchyByAreas(string[] areas)
{
}

I would like to create the following equivalent query in dotnet core

select * from StoreHierarchy
where AreaNbr in areas // (['13','12'....])

Since the parameter is string[] I would need to convert to an int[]. Is this query possible in either query or method synatx? If possible please provide both so I can compare.

Progman
  • 14,690
  • 4
  • 32
  • 46
Canolyb1
  • 610
  • 5
  • 16

1 Answers1

0

It's obvious:

public Task<IEnumerable<StoreHierarchy>> GetStoreHierarchyByAreas(string[] areas)
{
    var areasInt = areas.Select(a => int.Parse(a));
    return ctx.StoreHierarchy.Where(h => areasInt.Contains(h.AreaNbr));
}
Svyatoslav Danyliv
  • 13,476
  • 1
  • 9
  • 23
  • Thank you so much I was trying to do it this way: return ctx.StoreHierarchy.Where(h => h.AreaNbr.Contains(areaInt)); Now I realize the error in my ways . – Canolyb1 Jun 16 '21 at 18:30