-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
你好,试着看看内部的例外。 –
我该怎么做? –
在附加的图像中,剪贴板上有一个链接复制异常详细信息。点击它,然后粘贴到文本编辑器中 –