Can't find CreateQuery() method

Anyname Donotcare picture Anyname Donotcare · Jan 24, 2013 · Viewed 8.3k times · Source

I'm a new beginner to the entity framework .

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


enter image description here

why i can't find this method ?!!

Answer

manojlds picture manojlds · Feb 3, 2013

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<Person>("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<Blog> Blogs { get; set; }
    public DbSet<Post> Posts { get; set; }

    public ObjectContext ObjectContext()
    {
        return (this as IObjectContextAdapter).ObjectContext;
    }
}