How to convert DbSet in Entity framework to ObjectQuery

I found the answer. Of course, it is possible to convert DbSet in Entity framework to ObjectQuery using the below lines of code.

ObjectContext objectContext = ((IObjectContextAdapter)db).ObjectContext;  
ObjectSet<Request> objectSet = objectContext.CreateObjectSet<Request>("Requests");

where,

  • db – Context class inherting from DbContext.
  • RequestsDbSet<Request> defined in Context class.
  • objectSet – Can now be passed as ObjectQuery.

Leave a Comment