Когда мой код достигает CampaignRepository.saveChanges (), он выдает ошибку, что отношение не может быть изменено, ключевые свойства не могут быть нулевыми.Но если я отлаживаю его и смотрю содержимое текущего объекта, все первичные ключи и внешние ключи устанавливаются.Понятия не имею, почему все идет не так ...это toegestaan.Wanneer een reltie wordt gewijzigd, wordt de gerelateerde referentiële-sleuteleigenschap, принятый openen null-waarde.Как только он вылетел, он не имеет ничего общего с ним * не имеет смысла 100%.1009 *
Обновление
Я изменил свой метод обновления на:
public ActionResult Update(LandingPage update)
{
Campaign curr = Campaignrepository.FindById(update.CampaignId);
PageRepository.Remove(update);
curr.Pages.Remove(update);
curr.Pages.Add(update);
Campaignrepository.SaveChanges();
return View("Edit", curr);
}
Но теперь он говорит: «Объект не может быть удален, потому что он не найден вObjectManager ".
Обновление 2
Тем не менее" Объект не может быть удален, поскольку он не найден в ObjectManager ".
//A campaign has Pages property which is a collection of Pages
//This collection contains a two (no more, no less) objects a LandingPage and a RedeemPage
//both LandingPage and RedeemPage have as base Page
//The objective is to replace the old LandingPage with the new version
public ActionResult Update(LandingPage update)
{
//Get the campaign it's about
Campaign curr = Campaignrepository.FindById(update.CampaignId);
//Set the current Page his foreign key values to null
curr.GetLanding().Campaign = null;
curr.GetLanding().CampaignId = 0;
//Remove the (current) page from the repository/context
PageRepository.Remove(update);
//Remove the (current) page from the Campaign collection
curr.Pages.Remove(update);
//Add the new version of the page
curr.Pages.Add(update);
//Save the chances => ObjectManager error
PageRepository.SaveChanges();
return View("Edit", curr);
}