I have a Zero to one association between two tables. For instance, I have entity Car
and Entity License
and a car can have 0 or 1 License.
(A car can have one license, but a license can have 0 or 1 car) When I try to remove a car's license, by setting Car.License = null
i get an exception such as:
A relationship from the 'Car_Licence' AssociationSet is in the 'Deleted' state. Given multiplicity constraints, a corresponding 'License' must also in the 'Deleted' state.
I want the license to stay in the main Licenses DbSet, and i want it's reference to Car to remain, all I want it that the Car's license be set to null.
What am i missing?
Setting Car.License
to null
conflicts with association you have set, where car must have one license set. You need to change your association so that car can have one or zero licenses for it to work.
EDIT
You will have to set both ends of association to zero or one if you want to null the property.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.