I completed the tutorial hereto automatically generate my POCO classes from an existing MySQL database. The generated POCO classes worked as expected for all of my MySQL table objects. The database also has a rather complex, obsolete MySQL view that references 8 tables using both INNER and LEFT OUTER. The presentation itself is beautiful, and there are no problems when testing in MySQL Workbench. However, when I tried to select multiple records using the automatically generated POCO class for presentation, the operation was paused, even if its (hand-written) equivalent SQL statement worked perfectly and returned the required records very quickly, as expected. So I turned on logging in MySQL to check what was going on behind the scenes, and it turned out that the generated EF SQL was slightly different from what I expected.
My hand-written version was:
select a, b, c from MyView where a = 1
However, the generated version of EF was:
select Extent1.a, Extent1.b, Extent1.c from (select a, b, c from MyView) as Extent1 where Extent1.a = 1
This explains why I get a timeout because MyView has almost 1 million rows. However, I'm still wondering 1) why EF issues such an inefficient request and 2) how should I fix it.
I am using VisualStudio 2010 (currently cannot upgrade to 2012). NET Framework 4.0, EF 4.0 and EF 5.x DbContext Generator for C # (as suggested in the tutorial above)
source
share