Can't find CreateQuery() method

前端 未结 3 1744
北荒
北荒 2020-12-31 05:22

I\'m a new beginner to the entity framework .

and i can\'t find the following method CreateQuery()


3条回答
  •  礼貌的吻别
    2020-12-31 05:33

    Since ESQL was considered an advanced use case, there is no straightforward API from DbContext. You can access the ObjectContext that backs your DbContext to do what you want:

    ((IObjectContextAdapter)context).ObjectContext.CreateQuery("esql..")
    

    Related: http://thedatafarm.com/blog/data-access/accessing-objectcontext-features-from-ef-4-1-dbcontext/

    As suggested there, you can also add a method ( or property) ObjectContext to your context class:

    public class BloggingContext : DbContext
    {
        public DbSet Blogs { get; set; }
        public DbSet Posts { get; set; }
    
        public ObjectContext ObjectContext()
        {
            return (this as IObjectContextAdapter).ObjectContext;
        }
    }
    

提交回复
热议问题