var service = db.Services.Find(orderDto.IdService); var customer = db.Customers.Find(orderDto.CustomerId); var jobDay = db.JobDays.Find(id); order.Sum = orderDto.Sum; order.IsSale = orderDto.IsSale; order.IsCash = orderDto.IsСash; order.Service = service; order.JobDay = jobDay; order.Customer = customer; db.SaveChanges(); 

The Customer field is null . When you try to set it to null , it remains the same. How to win it?

  • Can you show the code where you assign the field a new value? There is a suspicion that you do not write changes to the context. In any case, without details to understand what the problem is impossible - eastwing
  • order.Customer = customer; the id comes is null, db.Customers.Find (orderDto.CustomerId); returns null and this null is assigned. I just wrote to check: order. Customer = null. It is installed, but only from the second time. - Qulac
  • Well, obviously, the problem is in orderDto.CustomerId - there is no entry in the database with such an ID, respectively, the search results are empty. Try to get a record for the beginning with a known index, and if everything orderDto out, sort out what's wrong with orderDto - eastwing

0