I'm developing a .NET application, and I have a problem. I try to populate a listbox from a MySQL database with Entity Framework. Here is my code:
public MainForm()
{
InitializeComponent();
try
{
hospitaldbEntities context = new hospitaldbEntities();
PatientlistBoxId.DataSource = context.patients;
PatientlistBoxId.DisplayMember = "FirstName";
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
I attach a picture from the Solution Explorer:
And finally here is my patient class:
public partial class patient
{
public patient()
{
this.examinations = new HashSet<examination>();
this.diseases = new HashSet<disease>();
this.drugsensitivities = new HashSet<drugsensitivity>();
}
public int PatientID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public System.DateTime DateOfBirth { get; set; }
public string Gender { get; set; }
public string Address { get; set; }
public System.DateTime DateOfCreate { get; set; }
public string Category { get; set; }
public int CNP { get; set; }
public virtual ICollection<examination> examinations { get; set; }
public virtual ICollection<disease> diseases { get; set; }
public virtual ICollection<drugsensitivity> drugsensitivities { get; set; }
}
Thank you for the help in advance.
EDIT
When I try to run the application, it throws an error: