Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 实体框架核心删除引用对象_Asp.net_Entity Framework Core - Fatal编程技术网

Asp.net 实体框架核心删除引用对象

Asp.net 实体框架核心删除引用对象,asp.net,entity-framework-core,Asp.net,Entity Framework Core,我有这个模型 public class Post { [Key] public int Id { get; set; } public string AuthorId { get; set; } public ApplicationUser Author { get; set; } public int ChannelId { get; set; } [Required] public Channel Channel { get; set;

我有这个模型

public class Post
{
    [Key]
    public int Id { get; set; }
    public string AuthorId { get; set; }
    public ApplicationUser Author { get; set; }
    public int ChannelId { get; set; }
    [Required]
    public Channel Channel { get; set; }
    [Required]
    public string Text { get; set; }
    public int CountViewers { get; set; } 
    public List<ApplicationUser> WhoLiked { get; set; }
    public DateTime Date { get; set; } = DateTime.Now;
}
当我将用户添加到某个帖子中的“Wholiked”列表时,EF会将该用户从其他帖子的列表中删除。 我做错了什么

   post.WhoLiked.Add(user);
   _db.Posts.Update(post);
   await _db.SaveChangesAsync();

我做错了什么?
← 我不知道你怎么期望没有直接访问你代码的人回答这个问题。请检查并提供一个。什么是
post
,它来自哪里,它包含什么?什么是
更新
?这不是标准的EF 6.x方法。预期的结果是什么?实际结果是什么?此外,您有两个对ApplicationUser(whoolike&Author)的引用。这需要特殊的配置。显示模型/fluent代码。
   post.WhoLiked.Add(user);
   _db.Posts.Update(post);
   await _db.SaveChangesAsync();