I'm creating an application that consists of multiple relations within my database.
I have an issue though in regards to trying to display a value from a corresponding table in my listview. This may sound confusing, but I will try to demonstrate now what I mean.
The image above shows my issue. I have two tables. A staff member and a Tutor group.
Within my viewmodel I use a method and within my view use and ObjectDataProvider which I assign to an ItemSource of my combobox to display a list of staff surnames, like so;
//...Listview...
<GridViewColumn Header="Staff Name" DisplayMemberBinding="{Binding StaffID}" />
//... window to add...
<ObjectDataProvider x:Key="Staff" ObjectType="{x:Type vm:TutorGroupViewModel}" MethodName="GetStaff"></ObjectDataProvider><ComboBox Grid.Column="1" Grid.Row="2" Name="cbStaffName" ItemsSource="{Binding Source={StaticResource Staff}}" DisplayMemberPath="Surname" SelectedValue="{Binding Path=StaffID, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True}" SelectedValuePath="StaffID" /> //... in VM ... public IEnumerable<DataObjects.Staff> GetStaff() { DBEntities context = new DBEntities(); return DesignerProperties.GetIsInDesignMode(Application.Current.MainWindow) ? Enumerable.Empty<DataObjects.Staff>() : (IEnumerable<DataObjects.Staff>)context.Staffs; }
As you can see though, it currently displays the staffs ID, rather then the name. Therefore, what I tried to do is that I created a property within my viewmodel and within my database table of the tutor, added another field called Surname.
However, when I make the changes within my view (which can be found here), I get the following inner exception;
The INSERT statement conflicted with the FOREIGN KEY constraint \"FK_TutorGroup_Staff\". The conflict occurred in database \"DB\", table \"dbo.Staff\", column 'StaffID'.\r\nThe statement has been terminated."
Therefore, how can i revolve this issue?
Thanks in advance.