0

I have a table User with a foreign key IDTown to a table of Town. They are in different datacontexts and i'm trying to edit them on usercontrol. i have a combobox that is working when adding a new user, but when i try to update Town i get an error from linq ForeignKeyReferenceAlreadyHasValueException. This is the combobox.

  <ComboBox x:Name="PlacesComboBox" SelectedValue="{Binding IDCity, Mode=TwoWay}" SelectedValuePath="ID" DisplayMemberPath="NameOfThePlace" ItemsSource="{Binding DataContext.AllPlaces, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"  />
Tseng
  • 61,549
  • 15
  • 193
  • 205
  • Welcome to SO. Please avoid forcing tags into the question title as per SO tagging guidelines. http://stackoverflow.com/help/tagging The tags on the lower end of the question are exactly for this :) – Tseng Feb 10 '16 at 15:15
  • This has got nothing to do with wpf or mvvm. The error has everything to do with linq to sql. You can probably find your answer at one of these questions http://stackoverflow.com/questions/2328413/linq-to-sql-foreignkeyreferencealreadyhasvalueexception-error/2328452#2328452 https://social.msdn.microsoft.com/Forums/en-US/c80a018b-0cfb-4c3f-be6c-3d5ea1dc3b30/linq-lookups-foreignkeyreferencealreadyhasvalueexception?forum=linqprojectgeneral –  Feb 10 '16 at 15:19
  • sorry for tags in title, new guy... – Marko Dragičević Feb 11 '16 at 07:31
  • @Will: You are right, it is a linq issue, and the model was generated using Linq to Sql classes. The problem is exception is raised on selection change in memory, and i have no code-behind. Can you help? – Marko Dragičević Feb 11 '16 at 07:57
  • Nope, not familiar with this error and I haven't used linq to sql in years. Didn't those links help at all? –  Feb 11 '16 at 14:13
  • Unfortunatelly no, this is the closest what i've gotten to googling but i just cant make it work: https://social.msdn.microsoft.com/Forums/en-US/7046a88a-6017-4b7c-9615-9e497a6593ec/foreignkeyreferencealreadyhasvalueexception-operation-is-not-valid-due-to-the-current-state-of-the?forum=wpf – Marko Dragičević Feb 11 '16 at 17:36

0 Answers0