找不到的createQuery()方法 [英] Can't find CreateQuery() method

查看:561
本文介绍了找不到的createQuery()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新的初学者到实体框架。

I'm a new beginner to the entity framework .

和我无法找到下面的方法的createQuery()

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

为什么我不能找到这个方法?!!

why i can't find this method ?!!

推荐答案

由于ESQL被认为是一种先进的使用情况下,有从的DbContext 没有直接的API。您可以访问的ObjectContext 的备份你的的DbContext 做你想要什么:

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..")

相关报道:<一href=\"http://thedatafarm.com/blog/data-access/accessing-objectcontext-features-from-ef-4-1-dbcontext/\">http://thedatafarm.com/blog/data-access/accessing-objectcontext-features-from-ef-4-1-dbcontext/

的建议那里,你还可以添加一个方法(或属性)的ObjectContext 对上下文类:

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;
    }
}

这篇关于找不到的createQuery()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆