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 mssql table

I use my MSSQL In the database, use the following code to get all the cities for each country

new country () {cities = obj.Counties SelectMany (E => E. Citys). Select (city = & gt; new dccity {name = city name, population = city.publication}}};

it has been returned as json

Enter image details here

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

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -