开发者

Entity Framework Not handling changes to a composite key

开发者 https://www.devze.com 2023-04-11 12:58 出处:网络
I have a class for a many-to-many relationship, like so: public partial class AdminBoundaryStaff { [Key, Column(Order=0)]

I have a class for a many-to-many relationship, like so:

public partial class AdminBoundaryStaff 
{
    [Key, Column(Order=0)]
    public int idAdminBoundary { get; set; }
    [Key, Column(Order = 1)]
    public int idAdminStaff { get; set; }
    [Key, Column(Order = 2)]
    public int idAdminStaffType { get; set; }

    public virtual AdminBoundary AdminBoundary { get; set; }
    public virtual AdminStaff AdminStaff { get; set; }
    public virtual AdminStaffType AdminStaffType { get; set; }

If I change the value of the idAdminStaff and post the form back to the controller, EF doesn't seem to see that there has been a change and doesn't even attempt a SQL update (watching it with profiler).

    [HttpPost]
    public ActionResult Edit( AdminBoundaryStaff adminboundarystaff)
    {
        if (Mode开发者_JAVA百科lState.IsValid)
        {
            db.Entry(adminboundarystaff).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
    }}
0

精彩评论

暂无评论...
验证码 换一张
取 消