How to convert DbSet in Entity framework to ObjectQuery

前端 未结 2 2104
北恋
北恋 2020-12-01 21:51

I am using CodeFirst approach and struck with an issue where I need to convert DbSet to ObjectQuery. This is what I did for conversion.

ObjectContext objectC         


        
2条回答
  •  余生分开走
    2020-12-01 22:12

    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 objectSet = objectContext.CreateObjectSet("Requests");
    

    where,

    • db - Context class inherting from DbContext.
    • Requests - DbSet defined in Context class.
    • objectSet - Can now be passed as ObjectQuery.

提交回复
热议问题