You received the value devicefrom the messages, and it is not tracked by context. Therefore, when you call db.SaveChanges, the context does not see any changes.
, branch_id device, id branch_id, .
:
device.branch_id = id;
db.Devices.Add(device);
db.SaveChanges();
:
device.branch_id = id;
db.Entry(device).State = EntityState.Modified;
db.SaveChanges();