-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
  • 16,827
  • 6
  • 33
  • 48
Canolyb1
  • 672
  • 5
  • 17

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
  • 21,911
  • 3
  • 16
  • 32
  • 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