工作人員只能有一輛車,車輛一次只能屬於一名工人。 有3層可能的實現我知道:
1.1對1關係
Vehicle(Id, Number)
Worker(Id, Name, VehicleId)
--> This allows two workers have the same vehicle.
2.
Worker(Id, Name)
Vehicle(Id, Number, WorkerId)
--> This allows worker to have two vehicles.
3.
Worker(Id, Name)
Vehicle(Id, Number)
WorkersVehicles(Id, VehicleId, WorkerId)
--> This allows each worker to have many vehicles and each vehicle to belong to many workers.
以上都不可以描述所期望的1:1的關係。
如何在數據庫和實體框架中描述這種1:1關係?
難道工人必須有車? – awright18