用数据库中的一个表填充WAF中的datagrid时遇到问题。 在数据库中,我创建了一些表,这些表引用了一个特定的列(Id_Exhibit)。
在用所需表填充数据网格的过程中,一切看起来都不错,但是其他引用的表也将其填充。
在我选择的所有列中都填充了数据库中特定表中的数据之后,出现了另一个表,这些表的名称都引用了Id_Exhibit列...
如何防止它们加载到datagrid中?
我的代码中没有太多,只有一种填充数据网格的方法
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MuzeumGUI
{
public partial class Exhibits: Form
{
public Exhibits()
{
InitializeComponent();
}
private void Ehxibits_Load(object sender, EventArgs e)
{
PopulateDataGridView();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
void PopulateDataGridView()
{
using (DBEntities db = new DBEntities())
{
dgvExhibits.DataSource = db.DBExhibit.ToList();
}
}
}
}
对于从我创建的实体生成的类,展览看起来像这样:
namespace MuzeumGUI
{
using System;
using System.Collections.Generic;
public partial class DBExhibit
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public DBExhibit()
{
this.DBRenovation = new HashSet<DBRenovation >();
this.DBReservation= new HashSet<DBReservation>();
this.DBRental= new HashSet<DBRental>();
}
public int Id_Exhibit { get; set; }
public string Name{ get; set; }
public string Era{ get; set; }
public string Description{ get; set; }
public string Creator{ get; set; }
public string Type{ get; set; }
public Nullable<int> Year { get; set; }
public string Century { get; set; }
public string Style { get; set; }
public string Status{ get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public ICollection<DBRenovation> DBRenovation{ get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public ICollection<DBReservation> DBReservation{ get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public ICollection<DBRental> DBRental{ get; set; }
}
}