You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there,
We are using this package in EF6 and it's working well, but running into trouble with where to register hooks exactly.
The logical place is in the constructor of the DbContext, but that can run into trouble as the very first time you construct the DbContext, the model may not have been created yet. This is a problem for unit tests.
Registering in OnModelCreating doesn't work either though.
public class MyDbContext : DbContext { public MyDbContext() { this.OnSave().Attach(new MyHook()); // Fails the first time the context is constructed, as model has not been created yet. } }
Wondering what strategy you take for registering the hooks.
Cheers
The text was updated successfully, but these errors were encountered:
Hi,
I've been using it from constructor, just like you do, but in code-first scenario.
You may try though registering hooks outside of MyDbContext class, e.g.
var dbContext = new MyDbContext();
dbContext.OnSave().Attach(new MyHook());
Could you provide more details on your unit tests scenario, or a sample project where I can check it?
Hi there,
We are using this package in EF6 and it's working well, but running into trouble with where to register hooks exactly.
The logical place is in the constructor of the DbContext, but that can run into trouble as the very first time you construct the DbContext, the model may not have been created yet. This is a problem for unit tests.
Registering in OnModelCreating doesn't work either though.
public class MyDbContext : DbContext { public MyDbContext() { this.OnSave().Attach(new MyHook()); // Fails the first time the context is constructed, as model has not been created yet. } }
Wondering what strategy you take for registering the hooks.
Cheers
The text was updated successfully, but these errors were encountered: