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 ??
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
EF 4.1 does not offer a public API to get the
DbContextfrom theDbSetinstance. You would have to use Reflections API to get theDbContextinstance.Edit
One workaround would be to pass around the
DbContextinstace withDbSetinstance.Eg if you had a constructor that took only a
DbSetinstance. Pass theDbContextinstace also.Other method would be to open up the
EntityFramewrk.dllinside Reflector and find out how to get theDbContextinstace by accessing the internal/private fields ofDbSet. I wouldn’t advice you to use this because implementations can change.