我有這樣的代碼和下面的EF模型:創建模型時分配FK導致「ReferentialConstraint中的依賴屬性映射到商店生成的列」。
var modelToAdd = new Package
{
PackageID = model.LearningPackageID, // not auto-generated PK!
Name = model.Name,
Description = model.Description,
DateCreated = DateTime.Now,
ModuleID = model.ModuleID
};
activityRepo.AddPackage(modelToAdd);
這不工作太
var modelToAdd = new Pacakge
{
PackageID = model.LearningPackageID, // not auto-generated PK!
Name = model.Name,
Description = model.Description,
DateCreated = DateTime.Now
};
// assume moduleID is defined to a valid module ID (yes, tested)
var module = entities.Modules.Where(x => x.ID == moduleID);
module.Pacakges.Add(modelToAdd);
entities.SaveChanges();
基本上,有一個1:高炮模塊和包品M的關係。然而,當我嘗試設置的moduleId(從下拉得到),這兩種情況下我會得到:
A dependent property in a ReferentialConstraint is mapped to a store-generated column.
包標識是字母數字,而不是自動生成的,要麼是的moduleId,如這是一個FK
我該怎麼辦?
因此,'Package'中的所有PK和FK都將'StoreGeneratedPattern'設置爲'None'? –