当我尝试添加 Venue 对象并调用 SaveChanges() 时,我不明白为什么会出现此错误。模型中与 Venue 对象的唯一区别是它们与 City 是 1 对 1..0 关系。
City city = ProcessCityCache(ev, country, db); // After this call, 'city' is already persisted.
venue = new Venue {
TicketMasterURL = ev.VenueSeoLink,
Name = Capitalize(ev.VenueName),
City = city
};
db.Venues.AddObject(venue);
db.SaveChanges(); // Exception thrown here.
任何见解将不胜感激!
(在其自己的选项卡/窗口中打开图像以查看完整尺寸)
最佳答案
我发现了问题。这都是我的错。我将我的 FK_Venue_City
关系设置为 City.ID
-> Venue.ID
我想要的是 City.ID
-> Venue.CityID
。我在我的数据库中进行了更改,然后更新了模型。
关于c# - ReferentialConstraint 中的依赖属性映射到存储生成的列。列 : 'ID' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6642566/