Home > Net >  EF Fluent API set foreign key problem
EF Fluent API set foreign key problem

Time:10-01

Table1 {int id, string name, string SFZH}
Table2 {int id, string xysfzh, string xyxx}
Table1 key=id
Table2 key=id
Set in table2 xysfzh associated is the foreign key in the table1 SFZH
O great god how to set up the foreign key?

CodePudding user response:

Attention to the primary key SFZH not table1

CodePudding user response:

See also: http://www.cnblogs.com/liuyuanhao/p/5501650.html

CodePudding user response:

I don't like the way with Fluent API to set up the correlation,
Personally, I used to attribute to set the
[ForeignKey]

CodePudding user response:

CodePudding user response:

CodePudding user response:

Similar to the following writing (Mapping) :
 
Enclosing HasRequired (t=& gt; Tc ategory)
WithMany (t=& gt; T.P roducts)
HasForeignKey (t=& gt; Tc ategoryID)
WillCascadeOnDelete (false);


OnModelCreating:
 modelBuilder. Entity (a). HasRequired (p=& gt; P.u ser.) WithMany (p=& gt; Conviction yourself etail). HasForeignKey (p=& gt; P.u id); 

CodePudding user response:

Good job
  • Related