Im trying to get a count on how many people live in a certain city. I have a database with people in it, and that table has a foreign key linking a certain person to a city, which is another table.
example:
City z: 5 people
City y: 10 people
City x: 4 people
im able to get these results back, but i just dont like the way i’m doing it, as i am calling the database x amount of times.
public List<int> getStuff(List<int> listOfCityIDs )
{
var returnList = new List<int>();
foreach (int z in listOfCityIDs)
{
returnList.Add((from x in conn.people
where x.city == z
select x).Count());
}
return returnList;
}
im pretty sure there’s a better/more efficient way of doing it with some LINQ, but i can’t seem to find how.
any ideas?
kind regards,
Jane
This will translate into SQL statements nicely.
This will get them all. If you want based for certain cities, try