2

I know this has been asked a lot before, but I still haven't found a working fix.

I'm creating a desktop application which will regularly be started and stopped. The database is a MySQL database stored online and I'm using the newest version of EF and the MySQL connector.

I'm also working code-first. For now, I only have 3 small entities, but these will grow a lot in time. The database is generated already at startup, so nothing needs to be created anymore.

Every time the application is started (even when deployed), retreiving the first data from the database (only like 50 records, but I've also tried only 10 and it doesn't make any difference) is slow: around 5 seconds. After that, the next queries are pretty fast (around 1 second).

I've already tried generating views, but it doesn't change anything. I also create only 1 DbContext.

If I attempt to use ADO.NET, I get the results almost instantly, even on the first query (retreiving all 50 records), so it has nothing to do with a connection issue.

I'm not sure what information I have to give in order for you to help me, so feel free to ask more info.

Any idea what I could try? Is it really supposed to take like 5 seconds before the user can start working with the program?

Bv202
  • 3,924
  • 13
  • 46
  • 80
  • See this - http://romiller.com/2014/06/10/reducing-code-first-database-chatter/ and if you do not need EF, dont use it... – ErikEJ Feb 05 '15 at 17:40
  • For testing, I've done the first step - setting the DatabaseInitializer to null. However, when I put a breakpoint, it doesn''t seem to get executed and there's no difference at all. I've placed the file in the same namespace as my context... any idea what I could be doing wrong? – Bv202 Feb 05 '15 at 17:52
  • Oh, I already know.. I have this attribute: [DbConfigurationType(typeof(MySqlEFConfiguration))] – Bv202 Feb 05 '15 at 18:01

1 Answers1

0

On EF the first a query is run it has to be compiled even though the program is already complied.

I would suggest reading this http://www.codeproject.com/Articles/38174/How-to-improve-your-LINQ-query-performance-by-X and this https://msdn.microsoft.com/en-us/library/vstudio/bb896297%28v=vs.100%29.aspx and trying again to see if this helps.

Good luck!

Martin
  • 660
  • 10
  • 23
  • 1
    Apparantly it's done automatically with EF6: http://stackoverflow.com/questions/26191721/entity-framework-6-compiled-linq-query – Bv202 Feb 05 '15 at 18:40