我遇到了這個錯誤,因爲標題說。我搜索谷歌,找不到答案,因爲如果我使用sql來插入,這是可以的,當我使用ef來添加時,它無法工作。在下面看,它是我的數據庫模式。 EF:「ReferentialConstraint中的依賴屬性映射到商店生成的列」Id變化
,當我嘗試添加一些好表,誤差occured.the良好的流暢API似乎是這樣的:
using ppdai.user.vip.model;
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Data.Entity.ModelConfiguration.Configuration;
namespace ppdai.user.vip.model.mapping
{
public class GoodsMapping: EntityTypeConfiguration<Goods>
{
public GoodsMapping()
{
this.Property(x => x.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
this.HasKey(x => x.Id);
this.Property(x => x.GoodsQuantity).IsRequired();
this.Property(x => x.GoodPrice).IsRequired();
this.Property(x => x.GoodScore).IsRequired();
this.Property(x => x.GoodTypeId).IsRequired();
this.HasRequired(x => x.GoodType)
.WithMany(x => x.Goods)
.HasForeignKey(x => x.GoodTypeId);
}
}
}
結果,好的是「中心」表的位置在我的數據庫中,任何人都知道如何解決它?
你用'.HasForeignKey(x => x.GoodTypeId)定義了foregin關鍵字;' –
@AliSoltani它與你提到的沒有任何關係,因爲我把外鍵關掉了,它仍然無法工作。 – MapleStory