问题描述
当我尝试添加Venue对象并调用SaveChanges()时,我无法弄清楚为什么会出现此错误.在带有Venue对象的模型中,唯一的区别是它们与City的关系为1:1..0.
I can't figure out why I get this error when I try to add a Venue object and call SaveChanges(). The only difference in the model with Venue objects is they are 1 to 1..0 relation with City.
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.
任何见识将不胜感激!
(在其自己的标签/窗口中打开图像以查看完整大小)
(Open the image in its own tab/window to see full size)
推荐答案
我发现了问题.这都是我的错.我将我的 FK_Venue_City
关系设置为 City.ID
-> Venue.ID
,其中我想要的是 City.ID
-> Venue.CityID
.我在数据库中进行了更改,然后更新了模型.
I found the problem. It was my fault. I had my FK_Venue_City
relationship set as City.ID
-> Venue.ID
where what I wanted was City.ID
-> Venue.CityID
. I made that change in my database then updated the model.
这篇关于ReferentialConstraint中的从属属性映射到商店生成的列.列:' ID'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!