Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 实体框架“;“数据库优先”;不生成外键_C#_Asp.net_Entity Framework 6_Visual Studio 2015 - Fatal编程技术网

C# 实体框架“;“数据库优先”;不生成外键

C# 实体框架“;“数据库优先”;不生成外键,c#,asp.net,entity-framework-6,visual-studio-2015,C#,Asp.net,Entity Framework 6,Visual Studio 2015,我使用了实体框架逆向工程,但它似乎遗漏了一些外键关系。 以下是我的数据库sql代码和生成的类: CREATE TABLE [dbo].[rapportAnomalie] ( [code_rapport] INT IDENTITY (1, 1) NOT NULL, [date_rapport] DATETIME NOT NULL, [etat] VARCHAR (50) NOT NULL, [code_agence] INT NOT N

我使用了实体框架逆向工程,但它似乎遗漏了一些外键关系。 以下是我的数据库sql代码和生成的类:

CREATE TABLE [dbo].[rapportAnomalie] (
[code_rapport] INT          IDENTITY (1, 1) NOT NULL,
[date_rapport] DATETIME     NOT NULL,
[etat]         VARCHAR (50) NOT NULL,
[code_agence]  INT          NOT NULL,
PRIMARY KEY CLUSTERED ([code_rapport] ASC),
CONSTRAINT [FK_rapportAnomalie_ToTable] FOREIGN KEY ([code_agence]) REFERENCES [dbo].[agence] ([code_agence])


CREATE TABLE agence
(
[code_agence] INT NOT NULL PRIMARY KEY, 
[intitule_agence] VARCHAR(100) NOT NULL, 
[adresse_agence] VARCHAR(100) NOT NULL
)
Agence.cs:

[Table("agence")]
public partial class agence
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    public int code_agence { get; set; }

    [Required]
    [StringLength(100)]
    public string intitule_agence { get; set; }

    [Required]
    [StringLength(100)]
    public string adresse_agence { get; set; }
 }
}
和reportrelation.cs:

[Table("rapportAnomalie")]
public partial class rapportAnomalie
{
    [Key]
    public int code_rapport { get; set; }

    public DateTime date_rapport { get; set; }

    [Required]
    [StringLength(50)]
    public string etat { get; set; }

    public int code_agence { get; set; }
}
}

有什么问题吗?

可能是一个重复的问题,链接如下

这里是上述链接的相关答案,我想这可能对你有价值


祝你好运

我只是手工编辑了它,添加了forgein键注释:

[Table("rapportAnomalie")]
public partial class rapportAnomalie
 {
    [Key]
    public int code_rapport { get; set; }

    public DateTime date_rapport { get; set; }

    [Required]
    [StringLength(50)]
    public string etat { get; set; }

    public int code_agence { get; set; }
    [ForeignKey("code_agence")]
    public agence agence { get; set; }
 }
}

您使用的EF版本是什么?实体框架6.1.3。