小编Gui*_*eto的帖子

实体类型"配置"需要定义主键

当我尝试使用时,Add-Migration我收到此错误:

实体类型"配置"需要定义主键.

现在,我知道实体需要钥匙,而且它有一个,但到目前为止,只是装饰一个属性[Key]完成了工作,但它似乎不再如此.所以我有以下实体:

public class Configuration
{
    [Key, ForeignKey("Client")]
    public int ClientId { get; set; }

    public CommunicationType CommunicationType { get; set; }

    public string CommunicationValue { get; set; }

    public virtual Client Client { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

但寻找了一段时间后,我发现,显然EF7不喜欢它的被违反约定,我需要重新命名ClientIdConfigurationId,但似乎错了我的编码约定.我是否必须改变我的方式,或者无论如何都要绕过这个?提前致谢.


编辑

这是Client实体,是的,那里有一个Configuration属性

public class Client
{
    [Key]
    public int ClientId { get; set; }

    public string Name { get; set; }

    public virtual User User { get; set; …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework entity-framework-core

6
推荐指数
1
解决办法
7793
查看次数