-1
這是我在通知控制器中的索引操作的代碼。如何避免asp.net mvc中的System.Data.Entity.Core.EntityCommandExecutionException?
public ActionResult Index()
{
//gets the current user
ApplicationUser currentUser = System.Web.HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());
//checks if the user is logged in
bool val1 = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
if (val1 == false)
{
return RedirectToAction("Login", "Account");
}
var myNotif = db.Notifications.Where(s => s.User1_Id == currentUser.Id || s.User2_Id == currentUser.Id).Where(s => s.Active_Status != currentUser.Id);
ViewBag.Autobots = new NotificationStatus[myNotif.Count()];
int i = 0;
foreach(var item in myNotif)
{
ViewBag.Autobots[i].name = db.Users.Where(x => item.Active_Status == x.Id).First().FirstName + " " + db.Users.Where(x => item.Active_Status == x.Id).First().LastName;
i++;
}
return View(myNotif.ToList());
}
private class NotificationStatus
{
string name;
}
我在這裏得到這個錯誤。那麼我該如何避免它?我試圖發送數據來查看,因此我使用的是字符串數組。我的Linq查詢是否錯誤? enter image description here
你好,試着看看內部的例外。 –
我該怎麼做? –
在附加的圖像中,剪貼板上有一個鏈接複製異常詳細信息。點擊它,然後粘貼到文本編輯器中 –