我正在使用此代碼來過濾Linq數據,並且它不斷崩潰。過濾Linq與Guid存儲在會話中
public ActionResult Index()
{
var model = db.Tickets
.Include(t => t.TicketNotes)
.Where(t => t.OpenUserId == Guid.Parse(Session["LogedUserID"] as string))
.OrderBy(t => t.OpenDate)
.ToList();
return View(model);
}
我得到的錯誤是:
'System.NotSupportedException' 類型發生在 EntityFramework.SqlServer.dll但在用戶代碼中沒有處理的例外
的我知道的錯誤是在這條線上:
.Where(t => t.OpenUserId == Guid.Parse(Session["LogedUserID"] as string))
public ActionResult Index()
{
var model = db.Tickets
.Include(t=>t.TicketNotes)
.Where(t.OpenUserId == new Guid("00000000-0000-0000-0000-000000000000"))
.OrderBy(t=>t.OpenDate);
return View(model);
}
絕對的,這就是爲什麼轉換需要LINQ表達式之前完成。 – Yuri
添加'.ToList()'將列舉整個表......如果它變得很大,這可能是最糟糕的事情。你的第二個例子更好...但它仍然在整個表上調用'.ToList()'... – entropic
@entropic感謝您突出顯示這一點,我在我的答案上添加了。在第二個例子中是複製粘貼錯誤(它不應該調用'.ToList()')非常感謝你發現這一點。 – adricadar