似乎无法使用此代码获取ApplicationDbContext
HttpContext.GetOwinContext().Get<ApplicationDbContext>();
Run Code Online (Sandbox Code Playgroud)
错误说没有Get()的重载方法使用0参数.不确定要传递的参数.
我试图使用与OWIN有链接的相同ApplicationDbContext,而不是创建一个额外的.
看起来在收到IQueryable之后,我无法修改查询以启用排序.这是代码片段.我的印象是,使用IQueryable(而不是IEnumerable)我应该能够做我正在尝试的事情.
using (oc1 = new NWEntities())
{
string customerid = "ALFKI";
var q = GetOrders((o) => o.CustomerID == customerid);
q.OrderBy(o => o.ShipCity); // DOES NOT WORK !!!!!!!!
foreach (var x in q)
{
Console.WriteLine(string.Format("Order#:{0} City:{1} for Customer {2}",
x.OrderID,
x.ShipCity,
customerid));
}
}
// Returns IQueryable
IQueryable<Order> GetOrders(Expression<Func<Order, Boolean>> predicate)
{
return (oc1.Orders.Where(predicate));
}
Run Code Online (Sandbox Code Playgroud)
输出以某种方式不按城市排序.我错过了一些明显的东西吗 感谢您的时间.