对不起标题,但我不知道如何提出问题。
控制器:
public ActionResult Chat() {
//get user first
User user = HttpContext.Session.GetObjectFromJson<User>("User");
//get all connections entrys with user
List<Connections> connList = (from c in _context.Connections
where (c.UserA_ == user || c.UserB_ == user)
select c).ToList();
List<User> userList = new List<User>();
//now i only want to save the other users and not user
foreach (Connections conn in connList) {
//HERE IS THE ERROR
if (conn.UserA_.Name == user.Name)
userList.Add(conn.UserB_);
else
userList.Add(conn.UserA_);
}
return View(userList);
}
表格
User: ID, Name, PW
Connections: ConnectionsID, UserA_ , UserB_
问题:
conn.UserA为空。
我想做什么:
我想获得与用户X连接的所有用户的列表,但老实说,我不知道我在这里做错了什么。
编辑: