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