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

The property 'Id' is part of the object's key information and cannot be modified.

4 Answers 1690 Views
EntityFrameworkDataSource
This is a migrated thread and some comments may be shown as answers.
Harald
Top achievements
Rank 2
Harald asked on 18 Sep 2016, 12:21 PM
In my application I have a RadGridView and a Data Form. If I change the group or type of the DocumentTitle on the CombBox in Data Form, I get the following error message:

"The property 'Id' is part of the object's key information and cannot be modified."

XAML-Code (DataGrid):

01.<telerik:RadEntityFrameworkDataSource Name="DocumentTitlesDataSource" QueryName="DocumentTitles">
02. </telerik:RadEntityFrameworkDataSource>
03.  
04.            <telerik:RadGridView x:Name="Entries" Grid.Row="1"
05.                             ItemsSource="{Binding DataView, ElementName=DocumentTitlesDataSource}"
06.                             SelectedItem="{Binding DataView.CurrentItem, Mode=OneWay, ElementName=DocumentTitlesDataSource}"
07.                             SelectionMode="Single"
08.                             IsReadOnly="True"
09.                             AutoGenerateColumns="False"
10.                             IsSynchronizedWithCurrentItem="True"
11.                             CanUserDeleteRows="False"
12.                             CanUserFreezeColumns="False"
13.                             CanUserInsertRows="False"
14.                             CanUserReorderColumns="False"
15.                             CanUserResizeColumns="False"
16.                             CanUserSortColumns="False"
17.                             CanUserSortGroups="False"
18.                             IsFilteringAllowed="False"
19.                             ShowGroupPanel="False"
20.                             ShowColumnHeaders="False" SelectionChanging="Entries_SelectionChanging">
21.                <telerik:RadGridView.Columns>
22.                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Id}" Header="Id" Width="20" IsVisible="False"/>
23.                    <telerik:GridViewDataColumn DataMemberBinding="{Binding User.Id}" Header="Benutzer" Width="10" IsVisible="False"/>
24.                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Computer}" Header="Computer" Width="10" IsVisible="False"/>
25.                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="Dokumententitel" Width="*"/>
26.                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Group.Id}" Header="Dokumentengruppe" Width="200"/>
27.                    <telerik:GridViewComboBoxColumn x:Name="cbxDocumentTitleGroup" DataMemberBinding="{Binding Group.Id}"
28.                                                    DisplayMemberPath="Name"
29.                                                    SelectedValueMemberPath="Id"
30.                                                    Header="Dokumentengruppe"
31.                                                    Width="100"/>
32.                    <telerik:GridViewComboBoxColumn x:Name="cbxDocumentTitleType" DataMemberBinding="{Binding Type.Id}"
33.                                                    DisplayMemberPath="Name"
34.                                                    SelectedValueMemberPath="Id"
35.                                                    Header="Dokumententyp"
36.                                                    Width="100" />
37.                    <telerik:GridViewDataColumn DataMemberBinding="{Binding System}" Header="System" Width="10" IsVisible="False"/>
38.                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Locked}" Header="Gesperrt" Width="10" IsVisible="False"/>
39.                </telerik:RadGridView.Columns>
40.            </telerik:RadGridView>

XAML-Code (DataForm):

01.<Grid.Resources
02.                <DataTemplate x:Key="WriteTemplate">
03.                    <Grid>
04.                        <Grid.ColumnDefinitions>
05.                            <ColumnDefinition Width="150"></ColumnDefinition>
06.                            <ColumnDefinition Width="*"></ColumnDefinition>
07.                        </Grid.ColumnDefinitions>
08.                        <Grid.RowDefinitions>
09.                            <RowDefinition></RowDefinition>
10.                            <RowDefinition></RowDefinition>
11.                            <RowDefinition></RowDefinition>
12.                            <RowDefinition></RowDefinition>
13.                            <RowDefinition></RowDefinition>
14.                        </Grid.RowDefinitions>
15.                        <Label Grid.Row="0" Grid.Column ="0" Margin="0,5,0,0">Dokumententitel:</Label>
16.                        <Label Grid.Row="1" Grid.Column ="0" Margin="0,5,0,0">Dokumentengruppe:</Label>
17.                        <Label Grid.Row="2" Grid.Column ="0" Margin="0,5,0,0">Dokumententyp:</Label>
18.                        <Label Grid.Row="3" Grid.Column ="0" Margin="0,5,0,0">Gesperrt:</Label>
19.                        <Label Grid.Row="4" Grid.Column ="0" Margin="0,5,0,0">Systemeintrag:</Label>
20.                        <telerik:DataFormDataField Grid.Row="0" Grid.Column ="1" DataMemberBinding="{Binding Name , Mode=TwoWay}" HorizontalAlignment="Stretch" LabelPosition="Above" Margin="0,5,0,0"/>
21.                        <telerik:DataFormComboBoxField Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch" LabelPosition="Above" Margin="0,5,0,0"
22.                                                       ItemsSource="{Binding ItemsSource, ElementName=cbxDocumentTitleGroup, Mode=TwoWay}"
23.                                                       DataMemberBinding="{Binding Group.Id}"
24.                                                       DisplayMemberPath="Name"
25.                                                       SelectedValuePath="Id"
26.                                                       SelectedIndex="{Binding Group}"/>
27.                        <telerik:DataFormComboBoxField Grid.Row="2" Grid.Column="1" HorizontalAlignment="Stretch" LabelPosition="Above" Margin="0,5,0,0"
28.                                                       ItemsSource="{Binding ItemsSource, ElementName=cbxDocumentTitleType}"
29.                                                       DataMemberBinding="{Binding Type.Id}"
30.                                                       DisplayMemberPath="Name"
31.                                                       SelectedValuePath="Id"
32.                                                       SelectedIndex="{Binding Type}"/>
33.                        <telerik:DataFormCheckBoxField Grid.Row="3" Grid.Column ="1" DataMemberBinding="{Binding Locked , Mode=TwoWay}" HorizontalAlignment="Stretch" LabelPosition="Above" Margin="0,5,0,0"/>
34.                        <telerik:DataFormCheckBoxField Grid.Row="4" Grid.Column ="1" IsReadOnly="True" DataMemberBinding="{Binding System , Mode=TwoWay}" HorizontalAlignment="Stretch" LabelPosition="Above" Margin="0,5,0,0"/>
35.                    </Grid>
36.                </DataTemplate>
37.            </Grid.Resources>   
38. 
39.        <telerik:RadDataForm x:Name="EntryDetails" Grid.Row="2" Header="Dokumententitel"
40.                             CommandButtonsVisibility="Cancel, Commit" AutoGenerateFields="False" AutoCommit="False"
41.                             EditEnding="EntryDetails_EditEnding"  ValidatingItem="EntryDetails_ValidatingItem" EditEnded="EntryDetails_EditEnded"
42.                             ReadOnlyTemplate="{StaticResource ReadTemplate}"
43.                             EditTemplate="{StaticResource WriteTemplate}"
44.                             NewItemTemplate="{StaticResource WriteTemplate}"
45.                             ItemsSource="{Binding DataView, ElementName=DocumentTitlesDataSource}"/>  

C# Code:

01.public DocimpDocumentTitles(VIMANTO.Environment My)
02.        {
03.            InitializeComponent();
04.            my = My;
05.            db.Database.Connection.ConnectionString = my.CurrentConnection.GetSqlConntectionString();
06.            DocumentTitlesDataSource.DbContext = db;
07. 
08.            ObservableCollection<CatalogEntry> documentTitleGroups = new ObservableCollection<CatalogEntry>();
09.            ObservableCollection<CatalogEntry> documentTitleTypes = new ObservableCollection<CatalogEntry>();
10. 
11.            documentTitleGroups = Database.Views.CatalogViews.GetCatalogEntries(my.CurrentConnection, VIMANTO.Database.Views.CatalogViews.GetCatalog(my.CurrentConnection, "Dokumentengruppen").Id, true);
12.            cbxDocumentTitleGroup.ItemsSource = documentTitleGroups;
13. 
14.            documentTitleTypes = Database.Views.CatalogViews.GetCatalogEntries(my.CurrentConnection, VIMANTO.Database.Views.CatalogViews.GetCatalog(my.CurrentConnection, "Dokumententypen").Id, true);
15.            cbxDocumentTitleType.ItemsSource = documentTitleTypes;
16.        }  

 

 

 

 

 

 

 

 

 

 

4 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 20 Sep 2016, 10:13 AM
Hello Harald,

The way the binding for the DataFormComboBoxFields is set when you change the selected item of the dropdown, you are actually trying to modify the Id of the bound Group/Type rather than update the GroupId/TypeId of the current Entry. That is why you're getting the error message you've described.

In order to avoid this, you should either bind to the GroupId/TypeId properties (if such exist) of the bound Entry objects or modify the declaration of the DataFormComboBoxField like so:

<telerik:DataFormComboBoxField DataMemberBinding="{Binding Group}" DisplayMemberPath="Name" SelectedValuePath="" />

Please let me know if any of these approaches work for you.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Harald
Top achievements
Rank 2
answered on 20 Sep 2016, 01:54 PM

After the change I get the following error message :
"The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects."

In my Project i am using the Entity Framework with Model First Workflow. I forgot to create the Foreign Key Property (see Screenshot).

New XAML Code:

1.<telerik:DataFormComboBoxField Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch" LabelPosition="Above" Margin="0,5,0,0" ItemsSource="{Binding ItemsSource, ElementName=cbxDocumentTitleGroup, Mode=TwoWay}" DataMemberBinding="{Binding GroupId}" DisplayMemberPath="Name" SelectedValuePath="Id"/>
2.<telerik:DataFormComboBoxField Grid.Row="2" Grid.Column="1" HorizontalAlignment="Stretch" LabelPosition="Above" Margin="0,5,0,0" ItemsSource="{Binding ItemsSource, ElementName=cbxDocumentTitleType}" DataMemberBinding="{Binding TypeId}" DisplayMemberPath="Name" SelectedValuePath="Id"/>

Now the problem is solved. Thank you.

0
Harald
Top achievements
Rank 2
answered on 20 Sep 2016, 01:58 PM

After the change I get the following error message :

"The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects."

In my Project i am using the Entity Framework with Model First Workflow. I forgot to create the Foreign Key Property (see Screenshot).

New XAML Code:

<telerik:DataFormComboBoxField Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch" LabelPosition="Above" Margin="0,5,0,0" ItemsSource="{Binding ItemsSource, ElementName=cbxDocumentTitleGroup, Mode=TwoWay}" DataMemberBinding="{Binding GroupId}" DisplayMemberPath="Name" SelectedValuePath="Id"/>
<telerik:DataFormComboBoxField Grid.Row="2" Grid.Column="1" HorizontalAlignment="Stretch" LabelPosition="Above" Margin="0,5,0,0" ItemsSource="{Binding ItemsSource, ElementName=cbxDocumentTitleType}" DataMemberBinding="{Binding TypeId}" DisplayMemberPath="Name" SelectedValuePath="Id"/>

Now the problem is solved. Thank you.

0
Dilyan Traykov
Telerik team
answered on 20 Sep 2016, 02:50 PM
Hello Harald,

I'm glad to hear you've resolved your issue. Do let me know if you need any additional assistance from my end.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
EntityFrameworkDataSource
Asked by
Harald
Top achievements
Rank 2
Answers by
Dilyan Traykov
Telerik team
Harald
Top achievements
Rank 2
Share this question
or