【发布时间】:2015-02-03 07:23:36
【问题描述】:
我正在尝试删除用户名 = 当前用户名的所有表数据。但是lambda表达式和转换有一些错误。“无法将源类型转换为目标类型。有帮助吗?
public JsonResult DeleteChatMessages(int id)
{
string toId = Session["SessionUserName"].ToString();
tblChat tblchats = _obj.tblChat.Where(p => p.ToId == toId);
_obj.tblChat.Remove(tblchats);
_obj.SaveChanges();
return this.Json(true, JsonRequestBehavior.AllowGet);
}
【问题讨论】:
-
将您的线路改为
tblChat tblchats = _obj.tblChat.FirstOrDefault(p => p.ToId == toId)
标签: c# asp.net-mvc linq controller