【发布时间】:2015-04-30 22:25:51
【问题描述】:
我正在开发一个 .NET 应用程序,但我遇到了问题。 我尝试使用实体框架从 MySQL 数据库填充列表框。 这是我的代码:
public MainForm()
{
InitializeComponent();
try
{
hospitaldbEntities context = new hospitaldbEntities();
PatientlistBoxId.DataSource = context.patients;
PatientlistBoxId.DisplayMember = "FirstName";
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
我附上来自解决方案资源管理器的图片:
最后是我的耐心课:
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; }
}
提前感谢您的帮助。
编辑
当我尝试运行应用程序时,它会引发错误:
【问题讨论】:
-
发生了什么?有什么错误?
-
我添加了更多细节。
-
异常告诉你确切地要做什么。
标签: c# .net entity-framework ado.net