I have following method
public SomeObj LoadSomeData(int id)
{
using (var context = new DataContext())
{
var result =
context.Database.SqlQuery<SomeObj>
($"SELECT * FROM SOMEOBJECT WHERE id = {id}")
return result;
}
}
This works fine, now the specification has changed, and I need to lookup multiple ids
. I get ids as list of int and return a list. I read a bit about Sql Query and I can use IN
and pass multiple values. So this is my changes:
public List<SomeObj> LoadSomeData(List<int> listOfIds)
{
using (var context = new DataContext())
{
var result =
context.Database.SqlQuery<SomeObj>
($"SELECT * FROM SOMEOBJECT WHERE id IN ({id})") <-- I am not sure how to pass list in
return result;
}
}
The second method works when I pass values manually to the query like 1,2,3 etc. but how can I pass list of to query?