Is there any way to analyze what entities have been loaded during one query request? Currently I'm using lazy loading and it has huge performance impact. So I would want to analyze query somehow and .Include all related objects.
Asked
Active
Viewed 85 times
0
-
Could you show your codes? – Apr 19 '14 at 17:02
-
possible duplicate of [Debugging Entity Framework SQL statements](http://stackoverflow.com/questions/7901814/debugging-entity-framework-sql-statements) – Josh Kodroff Apr 19 '14 at 17:04
-
I just want to get Entities that was loaded during my query. Is that possible? – Jeffrey Rasmussen Apr 19 '14 at 17:37
1 Answers
1
You can handle ObjectMaterialized
event of your context.
ObjectContext.ObjectMaterialized
PS. If you work with DbContext
, you need to retrieve ObjectContext
from it first:
var context = new YourDbContext();
var adapter = (IObjectContextAdapter)context;
var objectContext = adapter.ObjectContext;

Andrew
- 3,648
- 1
- 15
- 29
-
Looks like what I want! Let me check it and I'll get back and mark it as accepted answer! Thank you! – Jeffrey Rasmussen Apr 19 '14 at 18:25
-
1it will be raised for each single object retrieved as a result of query execution... – Andrew Apr 19 '14 at 18:28
-
1I'm not aware of functionality you are developing, but take a note of this remark from documentation to avoid possible bugs `" If an object with the same key value exists in the object context, the Entity Framework will not recreate the object and this event will not be raised. "` – Andrew Apr 19 '14 at 18:35
-
Yes, this is exactly what I need. Is there any way to get object hierarchy? I mean it raised with Entity only and I don't know which entity it was called from. For example I get raised event on Order entity and then on Customer. That would need to .Include("Order"."Customer") and so on.. – Jeffrey Rasmussen Apr 19 '14 at 18:53
-
1I think it is kind of tree - it first materializes parent entity and goes down. you can implement custom logic based on sequence of events raised and check what navigation properties are loaded. – Andrew Apr 19 '14 at 19:06