0

as a proof of concept I've changed my Model so that every entity derives from the abstract base class "TrackableEntity". Everything seemed to work fine in the beginning. While testing, I've encountered a severe performance problem when lazy-loading a simple navigation-property of an entity. The first time this association was called in the context it takes 10 seconds to load the related entity (from a table with only 5 entries!!). As it is a test system, there are only a total of 100 entries in the whole database.

Any ideas?

Thanx.

SolarX
  • 1,873
  • 2
  • 18
  • 26
  • 1
    I would suggest getting something like EFProf (http://efprof.com/) and checking out the SQL query that's being generated. It's a good possibility that it's generating some crazy SQL and you may need to rework your model to resolve that. – CodingGorilla Jul 13 '11 at 13:30
  • I used EFProf (Thanx for the Tip!) and all queries are reasonable fast. I think EF has as problem getting the metadata from the model the first time.? But I have pre-generated views already! – SolarX Jul 13 '11 at 14:38
  • When you step through the code, does that 10 seconds happen on a single line of code, or is it a cumulative thing? – CodingGorilla Jul 13 '11 at 14:39
  • It's a single line of code. "return EntityA.EntityB" where EntityA is loaded and I want to get EntityB (navigation property). – SolarX Jul 13 '11 at 14:41
  • You might try pre-generating the EF Views, see this article: http://blogs.msdn.com/b/adonet/archive/2008/06/20/how-to-use-a-t4-template-for-view-generation.aspx. You could verify that view generation is the issue by trying that line of code twice, the second time would theoretically be faster (because the view is cached). – CodingGorilla Jul 13 '11 at 14:44
  • As I said, I'm already using pre-generated views. And the second time the same line of code is real fast. Which makes no sense to me. I did put some breakpoint in the pre-generated view class just to see if it is used at all....but it is. – SolarX Jul 13 '11 at 14:47
  • Yea, sorry about that, my reading skills are a little lacking this morning. But now I'm out of ideas... – CodingGorilla Jul 13 '11 at 14:50
  • I use the same approach with Self Tracking Entities that all derive from a BaseEntity (modified the T4 template) but do not encounter such problems at all. Show some real code of querying the model, maybe something odd in there...for now I can't come up with any ideas unfortunately. – Youp Bernoulli Jul 13 '11 at 19:44
  • How does your inheritance works? You should not use entity inheritance for this because entity inheritance is treat completely differently (and more slowly - but not so much as you observe). – Ladislav Mrnka Jul 13 '11 at 20:37
  • I use "table per type strategy" for inheritance. – SolarX Jul 14 '11 at 08:15

1 Answers1

0

You're running under a debugger, right? If so, just manually pause it and display the stack. You will catch it in the act, and the problem will be on the stack. You might want to repeat this a few times, just to make sure. Here's why it works.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
  • But he will most probably see Entity framework in the stack. I don't think that removing entity framework is exactly what OP wants. – Ladislav Mrnka Jul 13 '11 at 20:36
  • @Ladislav: Every stack sample shows some things you don't want to remove. (`call _main`) However, if there is a statement in the program that is costing much time and can be optimized, it should also appear, unless it's one of those situations where the framework simply hides anything that serves as a function call stack of code the user wrote. – Mike Dunlavey Jul 13 '11 at 20:51