I’m creating a WPF application, allowing a user to enter in details using CRUD operation using Entity Framework (also using a Repository pattern).
So far, I’ve created an Application that allows a user to enter a Prospect client. I am able to edit this Prospect, add a new one and able to delete with ease.
This Prospect though has a Foreign Key relation within another table known as ProspectMeeting, taking the ProspectID from the Prospect table.
When I Select a Prospect from the ListView though, it doesn’t show the data of that selected Prospect.
The Image below is the image of the application in its current state – So hope that gives a better understanding of what I want to achieve.

In my repository I use this to get a List of ProspectMeetings using the ProspectID;
public List<ProspectMeeting> GetMeetingByProspect(int _ProspectID)
{
using (var context = new DBEntities())
{
return context.Prospects.First(i => i.ProspectID == _ProspectID).ProspectMeetings.ToList();
}
}
In my ProspectViewModel, I use this Observable Collection to get the data from the ProspectMeetingViewModel;
private ObservableCollection<ProspectMeetingViewModel> prospectMeetings = null;
public ObservableCollection<ProspectMeetingViewModel> ProspectMeetings
{
get { return GetProspectMeetings(); }
set
{
prospectMeetings = value;
OnPropertyChanged("ProspectMeetings");
}
}
internal ObservableCollection<ProspectMeetingViewModel> GetProspectMeetings()
{
ProspectMeetingRepository c = new ProspectMeetingRepository();
prospectMeetings = new ObservableCollection<ProspectMeetingViewModel>();
prospectMeetings.Clear();
foreach (DataObjects.ProspectMeeting i in c.GetMeetingByProspect(this.ProspectID))
{
ProspectMeetingViewModel prospectMeeting = new ProspectMeetingViewModel(i);
prospectMeeting.Prospect = this;
prospectMeetings.Add(prospectMeeting);
}
return prospectMeetings;
}
And in my ProspectListViewModel;
private ProspectListViewModel() : base("")
{
this.ProspectList = GetProspects();
}
private ProspectViewModel selectedProspect = null;
public ProspectViewModel SelectedProspect
{
get
{
return selectedProspect;
}
set
{
selectedProspect = value;
OnPropertyChanged("SelectedProspect");
}
}
private ObservableCollection<ProspectViewModel> prospectList = null;
public ObservableCollection<ProspectViewModel> ProspectList
{
get
{
return GetProspects();
}
set
{
prospectList = value;
OnPropertyChanged("ProspectList");
}
}
internal ObservableCollection<ProspectViewModel> GetProspects()
{
if (prospectList == null)
prospectList = new ObservableCollection<ProspectViewModel>();
prospectList.Clear();
foreach (DataObjects.Prospect i in new ProspectRepository().GetAll())
{
ProspectViewModel c = new ProspectViewModel(i);
prospectList.Add(c);
}
return prospectList;
}
I’ve been following this link to help me but I’ve become unstuck. Personally, When I look through my code, I think that it has something to do with the Repository not getting the data. But I am not too sure.
I hope some one could advice or me or help me with this issue. Firstly, sorry if this is a long question to take in and secondly if more code needs to be added then just let me know, I only added the data that I thought was appropriate.
Thanks in advance :).
The problem in the end was a binding issue. In my MainWindow.xaml i didn’t assign the ProspectMeetingListView to the
SelectedProspect, like so;Silly mistake from my behalf.