自从你
ToUsers
是
IEnumerable<NotificationToUser>
输入,你需要使用
ToList()
在你保存数据之前。在你的情况下
IQueryable<NotificationToUser>
之后
Select
.
修改代码如下:
if(submissionOwnerId != currentUser.Id)
{
notification.ToUsers = notification.ToUsers
.Append(new NotificationToUser { IsRead = false, UserId = submissionOwnerId })
.ToList()
}else//for the situation you do not need to append new NotificationToUser
{
notification.ToUsers = notification.ToUsers.ToList()
}
_context.Notifications.Add(notification);
_context.SaveChanges();