I have changed an existing project to use EF5 and code first. It is using a repository class which relies on the older ObjectContext. To keep the repository implementation the same I created a property on the DBContext which would return an ObjectContext:
public ObjectContext ObjectContext()
{
return (this as IObjectContextAdapter).ObjectContext;
}
The problem is that after this the entities are not available on the ObjectContext so the following code fails:
string GetSetName<T>() {
var entitySetProperty =
_context.GetType().GetProperties()
.Single(p => p.PropertyType.IsGenericType && typeof(IQueryable<>)
.MakeGenericType(typeof(T)).IsAssignableFrom(p.PropertyType));
return entitySetProperty.Name;
}
The original DBContext has all of the entities available before it is cast to an ObjectContext but as the ObjectContext class does not have the properties for my entities, how can I access them?