Multiplicity constraint violated Entity framework 5

前端 未结 1 2049
囚心锁ツ
囚心锁ツ 2020-12-11 16:53

Hello i have 3 classes Person, UserProfile(it inherits Person) and Results, a Person can have one or more results, when i try to add i a result to a person a i get the error

相关标签:
1条回答
  • 2020-12-11 17:27

    Are you trying to add the same Result to several users?

    In that case this will fail because entity framework will realize the Results collection of the Person class as a foreign key from Results to Persons. The mapping will be the same as if you add a Person navigation property to the Result class.

    If you want Person and Result to have a many-to-many relationship you have to add a ICollection<Person> Persons property to the Results class to make EF understand that.

    0 讨论(0)
提交回复
热议问题