更新表错误实体框架上的4列

时间:2014-10-30 22:37:57

标签: c# asp.net-mvc entity-framework

我正在尝试更新userprofile表上的4个字段,但是我收到以下错误

一个或多个实体的验证失败。有关详细信息,请参阅“EntityValidationErrors”属性。

我的UserProfile类由许多[Required]字段构成,但我只显示了四个

  1. 名字
  2. 电子邮件地址
  3. 网站
  4. 现在我的代码现在看起来像这样

     public void UpdateUserProfile(UserProfile userProfile)
        {
            using (var context = new Context())
            {
                context.UserProfile.Attach(userProfile);
    
                var entry = context.Entry(userProfile);
                entry.Property(e => e.Firstname).IsModified = true;
                entry.Property(e => e.Surname).IsModified = true;
                entry.Property(e => e.EmailAddress).IsModified = true;
                entry.Property(e => e.UserWebsite).IsModified = true;
    
                context.SaveChanges();
            }
        }
    

    我已经用Google搜索了错误,从我看到的内容看来,我需要加载与UserId链接的所有内容然后进行修改?但对我而言,只是为了更新四个领域似乎有点过头了?

    Image

0 个答案:

没有答案
相关问题