Yesterday, when working with some Entity Framework stuff, I tried to write this, and got the error "ObjectContext isn't a member" etc.
context.ObjectContext.Refresh(RefreshMode.StoreWins, myObject);
Now, context inherits the DbContext object, documented here: http://msdn.microsoft.com/en-us/library/system.data.entity.dbcontext(v=vs.103).aspx
This is normal inheritance of the "is a" type - my context object IS a DbContext object. The DbContext class implements the IObjectContextAdapter interface, so I would expect that the code above should work - the member function declared by the interface is required to be implemented in the DbContext class, or I would expect it to fail compilation with the "you must implement the interface" error. However, when we looked in the generated class definition, it wasn't there!
Eventually, I implemented the call like this, which the compiler accepted.
((IObjectContextAdapter)context).ObjectContext.Refresh(RefreshMode.StoreWins, myObject);
Can anyone explain why I had to do that, when the following code is the same situation and works fine?
interface IMyInterface {
int MyInterfaceMemberFunction();
}
public class MyObjectClass : IMyInterface {
public int MyInterfaceMemberFunction() { return 17; }
}
public class MyTestClass {
public int MyTestFunction() {
MyObjectClass m = new MyObjectClass();
return m.MyInterfaceMemberFunction(); //error here for EF context
}
}