这些是我的C#类,我使用MySql和EF:
---表---
int ID //(AI,PK)
Collection<C> cList
--- B表---
int ID // (AI, NN, UNIQUE)
int B1 //(pk)
int B2 //(pk)
Collection<C> cList
--- C表---
int ID //(AI, NN, UNIQUE)
int A_ID //(pk) - table A, field ID
virtual <A> objectA
int B_ID //(pk) - table b, field ID
virtual <B> objectB
表C映射:
HasKey(o => new { A_ID = o.A_ID, B_ID = o.B_ID });
Property(x => x.ID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
Property(x => x.A_ID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
Property(x => x.B_ID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
HasRequired(x => x.objectA).WithMany(x => x.cList).HasForeignKey(x => x.A_ID);//works
HasRequired(x => x.objectB).WithMany(x => x.cList).HasForeignKey(x => x.B_ID);//FAILS
我疯了,谷歌搜索,谷歌搜索和谷歌搜索......请帮忙!