I've got a database with a table of about 16,500 cities, and an EF Data Model (Database-First) for that database. I preload them into memory with the code:
Db.Cities.Load()
...then when it's time to use them, I've tried each of the following queries:
Dim cities() As String = Db.Cities.Select(Function(c) c.CityName).ToArray
Dim cities() As String = Db.Cities.Local.Select(Function(c) c.CityName).ToArray
The first query is fast (~10ms), but the second one takes about 2.3 seconds to run the first time (although it's faster than the first query when it's called after that).
This doesn't make sense because SQL Server Profiler verifies that the first query is hitting the database on another machine, but the second isn't!
I've tried turning off Db.Configuration.AutoDetectChangesEnabled
, and I've tried pre-generating the views.
What can I do to make .Local
faster? (Not all clients running this application are going to be on a fast LAN.)