i used to use the ObjectSet in EF 4.0, I could get the underlying Context for this ObjectSet using
myObjectSet.Context which returns ObjectContext.
Now with DbSet in Ef4.1, what is the equivalent ??
i used to use the ObjectSet in EF 4.0, I could get the underlying Context for this ObjectSet using
myObjectSet.Context which returns ObjectContext.
Now with DbSet in Ef4.1, what is the equivalent ??
EF 4.1 does not offer a public API to get the DbContext from the DbSet instance. You would have to use Reflections API to get the DbContext instance.
Edit
One workaround would be to pass around the DbContext instace with DbSet instance.
Eg if you had a constructor that took only a DbSet instance. Pass the DbContext instace also.
public MyService(DbContext context, DbSet<MyClass> mySet){}
Other method would be to open up the EntityFramewrk.dll inside Reflector and find out how to get the DbContext instace by accessing the internal/private fields of DbSet. I wouldn't advice you to use this because implementations can change.