Hi all,
I have an entity Assessment and an entity Comment. The entities are connected to eachother through an m:n relation. (The middle-table (=the one holding the 2 ID's) is called AssessmentComments)
In WPF, I have a gridview, which binds to the Assessment.CommentsViaAssessmentComments (this is the readonly collection created by llblgen).
Now I want to add a comment In Memory. I mean, I don't want to save to the database yet!!!
I read the documentation. More in particular the paragraph: How do I add an entity A to an entity B's collection of A's if A and B have an m:n relation ?. So I use this same method without saving the entity. But this way, there is one entity added to the AssessmentComments entityCollection, but the CommentsViaAssessmentComments entityCollection isn't updated! This way the wpf UI doesn't show the update.
Some code:
(codebehind)
void View_OnAddComment(object sender,EventArgs<string> e)
{
//create a CommentsEntity
CommentsEntity vCommentEntity = new CommentsEntity();
vCommentEntity.UserId = mAuthenticationService.UserId;
vCommentEntity.Timestamp = DateTime.Now;
vCommentEntity.Comment = e.Data;
//link the AssessmentsEntity and the CommentsEntity
AssessmentCommentsEntity vAssessmentCommentsEntity = new AssessmentCommentsEntity();
vAssessmentCommentsEntity.Assessments = View.Model.AssessmentFile.Assessments;
vAssessmentCommentsEntity.Comments = vCommentEntity;
View.Model.AssessmentFile.Assessments.AssessmentComments.Add(vAssessmentCommentsEntity);
}
(xaml)
<ListView Grid.Row="0" Grid.ColumnSpan="4"
ItemsSource="{Binding AssessmentFile.Assessments.CommentsCollectionViaAssessmentComments}"
IsSynchronizedWithCurrentItem="True" >
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Date" DisplayMemberBinding="{Binding Path=Timestamp}" />
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=UserId}" />
<GridViewColumn Header="Comment" DisplayMemberBinding="{Binding Path=Comment}" />
</GridView>
</ListView.View>
</ListView>
<Label Grid.Row="1" Grid.Column="0" FlowDirection="RightToLeft">:Add Comment</Label>
<TextBox Name="txtVehicleAddComment" Grid.Row="1" Grid.Column="1" />
<Button Name="btnVehicleAddComment" Click="AddComment" Grid.Row="1" Grid.Column="2" Width="50">+</Button>
Summerized: Q: How do I add an entity to an entitycollection that was created by an m:n-relation without saving to the database?
If you have any questions please let me know!
Kind regards,
Wim