Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

The property 'User_Id' is part of the object's key information and cannot be modified.

$
0
0

I am trying to replace a user  ID in a SQL Table column with another user ID but getting the Error "The property 'User_Id' is part of the object's key information and cannot be modified. "  Below is my code.

 using (var context = new Model())
            {
                var model = context.HeaderRoles
                    .Where(f => f.User_Id.Equals(OldUserId))
                    .ToList();
                model.ForEach(f => f.User_Id = NewUserId);
                foreach (var headerRole in model)
                    context.HeaderRoles.Add(headerRole);
                context.SaveChanges();

                return Json(model, JsonRequestBehavior.AllowGet);
            }

 


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>