Entity Framework 6中的CreateQuery在哪里

时间:2014-01-25 15:15:45

标签: frameworks entity createquery

简单的问题 - 实体框架6中的dbContext.CreateQuery方法在哪里?如果答案是没有这样的方法我的问题是如何通过SQL查询获取一些数据到objectQuery?

1 个答案:

答案 0 :(得分:0)

将上下文投射到IObjectContextAdapter并使用ObjectContext,例如:

        using (var context = new AdventureEntities())
        {
            string eSql = "SELECT VALUE c FROM AdventureEntities.Customer AS c ORDER BY c.LastName";
            var query = ((IObjectContextAdapter)context).ObjectContext.CreateQuery<Customer>(eSql);
            var customers = query.ToList();
            foreach (Customer customer in customers)
            {
                Console.WriteLine("{0}, {1}", customer.FirstName, customer.LastName);
            }
        }