I have a grid that is bound to a table in EF. I recently changed the design and I am getting the following exception.
Code behind:
And here as a screen shot of my EDM that I am referring to.
http://imgbin.org/index.php?page=image&id=16176
How can I achieve this kind of row insert? Thanks.
Entities in 'CFETSDBContainer.FREQUENCIES' participate in the 'FREQUENCYFreqPool' relationship. 0 related 'FreqPool' were found. 1 'FreqPool' is expected.
Why it is doing this is obvious, but I don't know HOW to fix it. When the user enters a new row in the data grid and commits it, it needs to create the new FREQ_POOL and FREQ_TYPE entries as well.
FREQ_POOL and FREQ_TYPE are base classes, and so I need to manually set the types of both and set their properties in the code-behind I believe.
How do I do this? I have only done simple databinding. Here is my code.
<
DataGrid
AutoGenerateColumns
=
"False"
Height
=
"278"
HorizontalAlignment
=
"Left"
Margin
=
"24,31,0,0"
Name
=
"dgIA"
VerticalAlignment
=
"Top"
Width
=
"520"
Loaded
=
"dataGrid1_Loaded"
RowEditEnding
=
"dgIA_RowEditEnding"
DataContext
=
"{Binding}"
>
<
DataGrid.Columns
>
<
DataGridComboBoxColumn
DisplayMemberPath
=
"Name"
Header
=
"GACC"
SelectedValuePath
=
"{Binding Name}"
x:Name
=
"cbGACCS"
SelectedValueBinding
=
"{Binding ZONE.GACC,Mode=TwoWay}"
/>
<
DataGridComboBoxColumn
DisplayMemberPath
=
"Name"
Header
=
"Zones"
SelectedValuePath
=
"{Binding Name}"
x:Name
=
"cbZONES"
SelectedValueBinding
=
"{Binding ZONE,Mode=TwoWay}"
/>
<
DataGridTextColumn
Header
=
"Frequency"
Binding
=
"{Binding Path=Frequency,Mode=TwoWay}"
/>
<
DataGridComboBoxColumn
Header
=
"Frequency Type"
x:Name
=
"cbFT"
SelectedValueBinding
=
"{Binding Path=FrequencyType,Mode=TwoWay}"
/>
<
DataGridComboBoxColumn
Header
=
"Owner"
x:Name
=
"cbOwner"
SelectedValueBinding
=
"{Binding Path=Owner,Mode=TwoWay}"
/>
<
DataGridTextColumn
Header
=
"Usage Type"
Binding
=
"{Binding Path=UsageType,Mode=TwoWay}"
/>
<
DataGridTextColumn
Header
=
"Comments"
Binding
=
"{Binding Path=Comments,Mode=TwoWay}"
/>
<
DataGridTextColumn
Header
=
"Serial #"
Binding
=
"{Binding Path=Serial,Mode=TwoWay}"
/>
</
DataGrid.Columns
>
</
DataGrid
>
private void dgIA_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
if (!isManualEditCommit)
{
isManualEditCommit = true;
DataGrid grid = (DataGrid)sender;
grid.CommitEdit(DataGridEditingUnit.Row, true);
ctx.SaveChanges();
isManualEditCommit = false;
}
}
}
And here as a screen shot of my EDM that I am referring to.
http://imgbin.org/index.php?page=image&id=16176
How can I achieve this kind of row insert? Thanks.