locked
Updating *..1 Entity Framework relation RRS feed

  • Question

  • sigh ...

    I'm all new to EF and WPF, and with everything new its giving me a hard time ...

    first off, this is my EDM: http://kraxn.t-h.cc/EDM.png

    i have a ListBox bound to 'CI_POSITION_ZIMMER'. inside that ListBox, i have ComboBoxes to select a 'CI_ZIMMER', and TextBoxes bound to 'KLAPPE'

    displaying the entities works fine, editing via the ComboBox bombs with a referential integrity constraint violation ("A referential integrity constraint violation occurred: A property that is a part of referential integrity constraint cannot be changed when the object has a non-temporary key."). chaning the text of the TextBox results in a 'The property 'KLAPPE' is part of the object's key information and cannot be modified.' exception ...

    i don't fully understand why this is happening, plus i don't know what to do about that. seems i need to intercept the setter somehow, and manually change the entity and re-attach it. the problem is, i don't know which event to intercept.

    this is the auto-generated 'CI_ZIMMER' property. the setter causes the exception mentioned above:

    /// <summary>
            /// There are no comments for CI_ZIMMER in the schema.
            /// </summary>
            [global::System.Data.Objects.DataClasses.EdmRelationshipNavigationPropertyAttribute("User_Manager_Reloaded", "CI_POSITION_ZIMMER_ZIMMER", "CI_ZIMMER")]
            [global::System.CodeDom.Compiler.GeneratedCode("System.Data.Entity.Design.EntityClassGenerator", "4.0.0.0")]
            [global::System.Xml.Serialization.XmlIgnoreAttribute()]
            [global::System.Xml.Serialization.SoapIgnoreAttribute()]
            [global::System.Runtime.Serialization.DataMemberAttribute()]
            public CI_ZIMMER CI_ZIMMER
            {
                get
                {
                    return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference<CI_ZIMMER>("User_Manager_Reloaded.CI_POSITION_ZIMMER_ZIMMER", "CI_ZIMMER").Value;
                }
                set
                {
                    ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference<CI_ZIMMER>("User_Manager_Reloaded.CI_POSITION_ZIMMER_ZIMMER", "CI_ZIMMER").Value = value;
                }
            }

    finally, this is my ListBox XAML:

    <ListBox Style="{DynamicResource SimpleListBox}" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding SelectedItem.CI_POSITION_ZIMMER, ElementName=CI_POSITIONListBox}">
       <ListBox.ItemTemplate>
          <DataTemplate>
             <StackPanel Orientation="Horizontal">
                <ComboBox Style="{DynamicResource SimpleComboBox}" Width="70" Margin="0,0,10,0" DisplayMemberPath="NR" SelectedValuePath="ID" SelectedItem="{Binding CI_ZIMMER, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Loaded="CI_ZIMMERComboBox_Loaded" ItemContainerStyle="{DynamicResource CIZIMMERComboBoxItemStyle}" />
                <TextBox Style="{DynamicResource SimpleTextBox}" Text="{Binding KLAPPE}" Width="40" />
             </StackPanel>
          </DataTemplate>
       </ListBox.ItemTemplate>
    </ListBox>

    any ideas? sigh :(

     

    thanks,

    Tom

    Wednesday, March 31, 2010 11:16 AM

Answers

  • ok. i'm giving up on composite keys. they make no sense to me anyways.

    i talked to the DB department and asked them if they could add an identity column for those tables in question. whatever is their opinion they where very cooperative and did that favor for me.

    no matter if composite keys make sense noways or not i'd still prefer my O/R mapper to handle them correctly, or better, easily.

    interestingly enough, typed DataSets caused less problems 5-6 years ago on composite keys than EF does in 2010.

    • Marked as answer by TomTom1234 Tuesday, April 6, 2010 12:38 PM
    Tuesday, April 6, 2010 12:07 PM

All replies

  • Hi,

    I have tried to reproduce your scenario but failed, could you please give us a simplified and ready-to-run example so that we can focus on the issue you are encountering more quickly?

    Thanks.

    Sincerely.


    Jim Zhou -MSFT
    Thursday, April 1, 2010 2:22 PM
  • Jim,

     

    what exactly did you try to reproduce and where did you fail? by saying you failed to reproduce the scenario, do you mean you managed to successfully update an entity with 4 keys?

    how could i, in this specific scenario, get you a ready-to-run example?

     

    also, is it somehow possible to tap into the binding engine using an event? the exceptions are thrown even before my binding converter fires :(

     

    thanks,

    Tom

    Tuesday, April 6, 2010 5:09 AM
  • ok. i'm giving up on composite keys. they make no sense to me anyways.

    i talked to the DB department and asked them if they could add an identity column for those tables in question. whatever is their opinion they where very cooperative and did that favor for me.

    no matter if composite keys make sense noways or not i'd still prefer my O/R mapper to handle them correctly, or better, easily.

    interestingly enough, typed DataSets caused less problems 5-6 years ago on composite keys than EF does in 2010.

    • Marked as answer by TomTom1234 Tuesday, April 6, 2010 12:38 PM
    Tuesday, April 6, 2010 12:07 PM