Simple question - where is dbContext.CreateQuery method in Entity Framework 6 and if the answer is there is not such method my question is what to do to get some data by SQL query to an objectQuery?
Asked
Active
Viewed 2,607 times
2
-
Check out this post: http://stackoverflow.com/questions/14506161/cant-find-createquery-method – Laszlo Sep 24 '14 at 07:33
1 Answers
0
Cast context to IObjectContextAdapter
and use ObjectContext
, e.g.:
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);
}
}

user2341923
- 4,537
- 6
- 30
- 44