c# - Entity Framework: Query is slow -
I have some problems with the entity framework. I have made it easy to explain to simplify.
These are my mssql tables
I use my MSSQL In the database, use the following code to get all the cities for each country
it has been returned as json
There are more than 40,000 records in the city table It takes about 8 seconds to recover a list with all countries and their respective cities, I am trying to reduce it. To know all the data, you should first ask the table of cities:
/ P>
var city = _context.Cities.Select (x = & gt; new {ContryId = x country.name Country ID, ContryName = x.County.Country.Name, CityId = x ID , Citizen = x.Name}); Var DesertType = New Dictionary & lt; int, Dansdt & gt; (almost countOfCountries); foreign city (different cities in the city) [country country; if (! CountryLookup.TryGetValue (city. CountryId, out of country)) {country = new countrydown {name = city} Country name, id = city Country country = new list & amp ;;; Citidotti & gt; (Approx. CountOfCities)}; Country Show Add (country.id, country); } Country.Cities.Add (New CityDto {name = city.Name, id = city.Id}); }
The result will be:
countryookup.values
Comments
Post a Comment