2
我開始使用EF 4.1代碼。EF中的複合鍵是否工作?
我有一個實體表是這樣的:
public AMapping()
{
Property(x => x.Counter).IsRequired();
HasKey(x => x.AID);
HasKey(x => x.BID);
HasRequired<A>(x => x.A)
.WithMany(y => y.CList)
.HasForeignKey(f => f.AID);
ToTable("A");
}
表中的列是這個樣子:
AID(PK, FK, int, not null)
Counter(int, not null)
BID(PK, FK, int, not null)
在寫保存集成測試它給以下錯誤:
Cannot insert the value NULL into column 'BID', table 'Sprint3.dbo.A'; column does not allow nulls. INSERT fails.
但我可以看到我傳遞了一個整數值。
首先在EF 4.1代碼中對複合主鍵有任何約束嗎?
謝謝...這並解決它。 – alice7