c# - 防止在数据网格中加载引用的表格
问题描述
使用数据库中的一张表填充 WAF 中的数据网格时出现问题。在我的数据库中,我创建了几个引用一个特定列 (Id_Exhibit) 的表。
在使用所需表填充我的数据网格期间,一切看起来都很好,但其他引用的表也会填充它。
在我选择的所有列都填充了来自数据库中特定表的数据之后,就会出现另一个具有引用 Id_Exhibit 列的表的名称...
如何防止它们加载到数据网格中?
我的代码中没有太多内容,只有一种填充数据网格的方法
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();
}
}
}
}
至于从我创建的实体生成的类,Exhibit 如下所示:
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; }
}
}
解决方案
推荐阅读
- slack - 防止 Slack 在每次单击单选按钮后发送请求
- python - Python Pandas:根据前一行的重复值删除行
- c# - 为什么我不能在扩展方法中更新字符串的值?
- reactjs - ts-mocha 和 chai - 错误 TS2695:逗号运算符的左侧未使用且没有副作用
- allennlp - Predictor.from_archive 失败
- javascript - A-frame 在功能上添加启用/禁用组件
- ffmpeg - 如何将所有音轨合并为一个
- discord.py - 齿轮不和谐中的狙击命令,py
- python - 打印排序数字列表中的中间整数
- python - 如果行中的最后一列为 NULL,则通过 MySQL 'LOAD DATA' 命令加载 NULL 值不起作用