如何限制实体框架读取从汽车到汽车(例如)的外键关系为0..1 -> 1
而不是* -> 1
?实体框架约束基数
我有表
create TABLE [dbo].[Vehicles](
[Id] [int] IDENTITY(1,1) NOT NULL primary key,
<rest of the columns>
)
create TABLE [dbo].[Cars](
[Id] [int] NOT NULL,
<rest of the columns>
)
键和外键:
alter table [Cars] add foreign key(id) references [Vehicles](id)
,当我创建一个数据库中的模型,它是作为* -> 1
创建我不能改变:
我知道我手动更改关联een这两个实体,但它并不重要,因为它不会改变约束
我需要这样做,将baseType属性Cars
设置为Vehicle
以实现继承。
目前我得到这个错误:
Multiplicity is not valid in Role 'BoatsTPT' in relationship 'FK__BoatsTPT__Id__117F9D94'. Because the Dependent Role refers to the key properties, the upper bound of the multiplicity of the Dependent Role must be 1.
难道你可以将Cars的PK设置为车辆表格PK的FK,并且两者不能为NULL。 如果您在汽车表上制作车辆[Id]单独列,它应该可以工作。 – Qpirate