Many to Many (Students , classes example) DataGridComboBoxColumn binding problem RRS feed

  • Question

  • I have a WPF / entity framework application, my model have student , class entities there is a many to many association/relation between student and class (student can have many classes and class have many students )

    student [ Id ,Name , Classes(Navigation property) ] classes [ Id ,Title, Students(Navigation property ]

    in this case the entity framework don't show the join/relation table.

    i have a 2 DataGirds as master details, student grid is the master and classes is details

         <StackPanel DataContext="{StaticResource studentViewSource}"
                    <DataGrid x:Name="StudentsDataGrid"
                            <DataGridTextColumn x:Name="idColumn"
                                                Binding="{Binding Id}"
                                                Width="SizeToHeader" />
                            <DataGridTextColumn x:Name="nameColumn"
                                                Binding="{Binding Name}"
                                                Header="Student Name"
                                                Width="*" />
                            <DataGridTextColumn x:Name="phonesColumn"
                                                Binding="{Binding Phones}"
                                                Width="200" />
                    <DataGrid x:Name="StudentclassesDataGrid"
                              ItemsSource="{Binding Source={StaticResource studentClassesViewSource}}"
                            <DataGridComboBoxColumn Header="Class Name From Combo"
                                                    ItemsSource="{Binding Source={StaticResource classViewSource}}"
                                                    SelectedItemBinding="{Binding Classes}" />
                    <Button Content="Save"
                            Click="Button_Click" />

    I have 2 problems in the classes datagird :

    the DataGridComboBoxColumn don't display the name of the class the student registered in?

    When I register a student with new class (creating new row in the DB and selecting a class name ) when I try to save the changes to DB I got error message :Validation failed for one or more entities. See 'EntityValidationErrors' property for more details

    Friday, September 13, 2013 4:08 PM

All replies

  • you should post to the MSDN EF forum.
    Friday, September 13, 2013 6:06 PM
  • EF Generate POCO classes ,i don't think it's EF thing
     public partial class Student
            public Student()
              this.Classes = new ObservableCollection<Class>();
            public int Id { get; set; }
            public string Name { get; set; }
            public string Phones { get; set; }
            public virtual ObservableCollection<Class> Classes { get; set; }
     public partial class Class
            public Class()
              this.Students = new ObservableCollection<Student>();
            public int Id { get; set; }
            public string Name { get; set; }
            public System.TimeSpan Duration { get; set; }
            public virtual ObservableCollection<Student> Students { get; set; }

    Saturday, September 14, 2013 7:56 AM
  • Anyone ?? help :(
    Monday, September 16, 2013 11:55 AM
  • I've Uploaded the project files

    project files

    its very simple and straightforward,

    Wednesday, September 25, 2013 8:09 AM