This is a migrated thread and some comments may be shown as answers.

DataFormComboBoxField: ForeignKeyReferenceAlreadyHasValueException

1 Answer 129 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Gerrit
Top achievements
Rank 1
Gerrit asked on 24 Oct 2012, 09:32 AM
Hello,

we currently have the following problem:

There is a table named ST_Classification and one named ST_Address, which have the following relationship:
ST_classification.PK_classification -> ST_Address.FK_classification

In a WPF-Application there is a DataFormComboBoxField which is populated with data from the ST_Classification table.
The moment the value is set to a new one an exception is thrown:
System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException was unhandled by user code
Message=Operation is not valid due to the current state of the object.


This is code in the xxx.designer.cs where the exception is thrown:
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_FK_classification", DbType="BigInt", UpdateCheck=UpdateCheck.Never)]
        public System.Nullable<long> FK_classification
        {
            get
            {
                return this._FK_classification;
            }
            set
            {
                if ((this._FK_classification != value))
                {
                    if (this._ST_classification.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnFK_classificationChanging(value);
                    this.SendPropertyChanging(); // <--- Exception is thrown!
                    this._FK_classification = value;
                    this.SendPropertyChanged("FK_classification");
                    this.OnFK_classificationChanged();
                }
            }
        }


This is the XAML-code for the DataFormComboBoxField:
<telerik:RadDataForm x:Name="RDF_ST_Addresse" ItemsSource="{Binding Items, ElementName=RG_ST_Partner}"
 AutoGenerateFields="False"
 EditEnding="RDF_ST_Addresse_EditEnding"
EditEnded="RDF_ST_Addresse_EditEnded"
DeletingItem="RDF_ST_Addresse_DeletingItem"
ValidatingItem="RDF_ST_Addresse_ValidatingItem"
AddingNewItem="RDF_ST_Addresse_AddingNewItem"
AddedNewItem="RDF_ST_Addresse_AddedNewItem" >
.
.
.
<telerik:DataFormComboBoxField DataMemberBinding="{Binding FK_classification, Mode=TwoWay}"  Name="DFCMB_classification"
Label="Klassifikation" IsReadOnly="False"
SelectedValuePath="PK_classification"
DisplayMemberPath="classification" Initialized="DFCMB_classification_Initialized" />

Here is the codeBehind for DataFormComboBoxField:
private void DFCMB_classification_Initialized(object sender, EventArgs e)
            {
                ((DataFormComboBoxField)sender).ItemsSource = from p in goDCAddach.ST_classifications orderby p.classification     select p ;
            }

 Thanks for any help in advance.

Greetings
Gerrit

1 Answer, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 24 Oct 2012, 10:09 AM
Hello Gerrit,

Would it be possible for you to send us a simple repro project via a support ticket, so that we could debug it on our side?

Kind regards,
Ivan Ivanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
DataForm
Asked by
Gerrit
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Share this question
or