Foreign key constraint, EF with collection of childobjects

后端 未结 4 1437
遥遥无期
遥遥无期 2021-01-27 09:31

I\'m trying to update a model, but get the error \"The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable.

4条回答
  •  萌比男神i
    2021-01-27 09:39

    One thing of note is that you shouldn't have the [Required] on Customer as its inferred from the fact that your FK isn't nullable. Required should only be used on a navigation property if you do not have the FK in the model.

    To try to diagnose the issue, can you load the object and look at it in a debugger, you should expect that both locationId and CustomerId have non-zero values.

提交回复
热议问题