[英]Entity Framework “Database First” not generating Foreign keys
I used entity framework reverse engineering but it seems to miss some foreign key relations. 我使用实体框架逆向工程,但似乎错过了一些外键关系。 Here are my database sql code and the generated classes: 这是我的数据库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: 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; }
}
}
and Rapport.cs: 和Rapport.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; }
}
}
what could be the problem there? 那里可能是什么问题?
Probably a duplicate question with the following link The question posed on stack over flow 带有以下链接的重复问题
And here the related answer of the above link which I guess could be of value for you EF Reveres Engineering 在这里,我想上述链接的相关答案对您很有价值EF Reveres Engineering
Good luck 祝好运
I just ended up editing it manually adding the forgein key annotation: 我刚结束手动编辑它,添加了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; }
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.