Search code examples
c#.netentity-frameworkentity-framework-4

A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'ID'


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.

Any insight would be greatly appreciated!

Model Diagram

(Open the image in its own tab/window to see full size)


Solution

  • 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.