I have again ran into problems with Entity Framework phew....
I am trying to update a table with a foreign key,
I had problems with Inserting but that got sorted by editing the edmx file.
I am using the following code to update User table which has a foreign relationship to role table,
Domain.Data.Role role = db.Role.FirstOrDefault(r => r.RoleName == user.Role);
Domain.Data.User data = db.User.Where(u => u.UserName == username).First();
data.Pass = user.Password.Encrypt();
data.CreatedBy = Login.User.Encrypt();
data.DtCreated = DateTime.Now;
//data.Role = role;
data.Role = (from r in db.Role
where r.RoleName == user.Role
select r).First();
db.SaveChanges();
On updating I am getting the following exception,
A referential integrity constraint violation occurred: A property that is a part of referential integrity constraint cannot be changed when the object has a non-temporary key.
Any feedback will be very helpful.
Regards,
Sab