Mkl Rjv
Mkl Rjv

Reputation: 6933

Check if and interceptor has been applied to a context

I have an Entity Framework context which inherits from ObjectContext and I am adding an interceptor to the same. But, the interceptor gets added multiple times. Is there a way to add the interceptor to the context only once while its being declared? Or as an alternative, is there a way to check if a context already has an interceptor attached to it?

Upvotes: 0

Views: 633

Answers (1)

Ivan Stoev
Ivan Stoev

Reputation: 205719

Ok, so you are using DbInterception.Add method to add interceptors.

Unfortunately there is no Contains method or any way to enumerate the interceptors.

The only way I see is to call DbInterception.Remove before adding the interceptor. But it will require your interceptors to override Equals method and compare by type or something else based on their content, i.e. compare by value rather than by reference.

Upvotes: 1

Related Questions