根据用户帖子的增加增加用户的积分

Increment user's points based on increase in user's posts

我有一个简单的用户,具有以下字段----

   public class User
    { 
      public User()
      {
       this.Posts = new HashSet<Post>();
       }
    [Key]
    public int UserId { get; set; }
    public string UserName { get; set; }
    public string Password { get; set; }
    piblic int point {get; set;}
    public virtual ICollection<Post> Posts { get; set; }
    }
}

然后,我有一个 post table 对应于用户这样的东西---

 public class Post
 { 
   public Post()
   {
      public int PostId { get; set; }
      public string Message { get; set; }
      public int PostedBy { get; set; }
      public virtual User User { get; set; }
   }
 }

现在,用户和 posts table 之间存在一对多关系。 1个用户可以有多个posts.Now,我想根据用户post在post秒Table.Suppose的增量来增加用户的积分,一个用户posted 5posts 在某些问题上然后我想将他的分数从 0 增加到 25 意味着每 posts,增加 5. 到目前为止我尝试过的是这个查询-----

    from p in Posts
    join u in UserProfiles
    on p.PostedBy equals u.UserId
    where p.PostedBy == 1
    group p by p.PostedBy into dups 
    let totalcount = dups.Count()
    select totalcount

1>现在,我想将这个总计数值(输出)分配给 UserProfilesTable 中的用户点列,并将该值保存到数据库中。 非常感谢!

public class User
{ 
    public User()
    {
        this.Posts = new HashSet<Post>();
    }
    [Key]
    public int UserId { get; set; }
    public string UserName { get; set; }
    public string Password { get; set; }
    public int point {get { return this.Posts.Count*5; } }
    public virtual ICollection<Post> Posts { get; set; }
}

这是一个 LINQ 查询:

var user = db.UserProfiles.Select(up=> new User {
  UserId=up.UserId,
  UserName=up.UserName,
  Password=up.Password, //Really?
  point=up.Posts.Count()*5,
  });