是否可以在没有主键的情况下创建多对多对象?

问题描述 投票:0回答:1

我的数据库中有驱动程序和许可证代码,其中许多驱动程序可以具有许多许可证代码。

[在许多不同的地理区域(例如,美国各州)也有多个驾驶执照代码的情况,因此我需要为每个执照代码标识区域。

我的老板建议我建立一个联接表,该表只列出外键。此类的POCO模型如下所示(我使用虚拟属性是因为我很懒):

public class CountryLicenseCodes
{
    public virtual LicenseCode LicenseCode { get; set; }
    public virtual Country Country { get; set; }
    public virtual Region Region { get; set; } // This is the State/Province where the license applies.
}

这显然在EF中不起作用,因为EF需要PK值。我非常愿意为该模型添加Id属性来满足该要求,但是有没有办法我可以做到这一点吗?

c# entity-framework-6
1个回答
0
投票

没有主键,您将无法创建数据库表。它需要一个标识符

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.