2

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

4

1 回答 1

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);
            }
        }
于 2015-09-17T12:07:25.560 回答