Can someone help me with a work-around for this issue?
I have the following class:
public partial class FObjectSet<T> : IObjectSet<T> where T : class
{
...
}
I also have the following class:
public partial class FContext : IContext, IDisposable
{
public ObjectSet<T> CreateObjectSet<T>() where T : class
{
var fakeObjectSet = new FObjectSet<T>();
return (fakeObjectSet as IObjectSet<T>) as ObjectSet<T>;
}
}
The CreateOjectSet method returns a null as the cast is not working.
p.s. The code above is trying to fake the System.Data.Objects.ObjectContext.CreateObjectSet method.
In your example, FObjectSet does not appear to inherit from ObjectSet. It only implements the IObjectSet interface.
If it did inherit from ObjectSet, you wouldn’t need to cast it to a IObjectSet before casting it to an ObjectSet, in fact, you wouldn’t need to cast it at all…