Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to subscribe to ObjectMaterialized using EF6?

I'm trying to subscribe my context to the OnjectMaterialized event following this, like so:

((IObjectContextAdapter)this).ObjectContext
                             .ObjectMaterialized += ObjectContext_OnObjectMaterialized;

But I'm using EF6 and the OnContextCreated method mentioned on that post does not exists in this version.

I tried subscribing the materialized event at the context constructor, but then, if the database is deleted (which we do often during integration tests), the event is no longer subscribed. We tried subscribing again after Database.Delete() but it doesn't work either.

So my question is, where should I properly subscribe the ObjectMaterialized event using Entity Framework 6?

like image 896
fdiaz Avatar asked Feb 09 '14 20:02

fdiaz


1 Answers

Could you simply subclass the context and subscribe to the event in the constructor? (I've done this and it works for my scenario. YMMV.)

like image 170
wintermute Avatar answered Sep 20 '22 12:09

wintermute