0
我有編碼代表我的SQL表我自己的對象,其中包括如下如何篩選詳細記錄了主從關係使用LINQ
[Table(Name = "tbl_employee")]
public class employee
{
private EntitySet<workDay> _hours;
public employee()
{
this._hours = new EntitySet<workDay>(OnDtlAdded, OnDtlremoved);
}
private void OnDtlAdded(workDay addedDtl) { addedDtl.Employee = this; }
private void OnDtlremoved(workDay removedDtl) { removedDtl.Employee = null; }
[Association(ThisKey = "employeeID", Storage = "_hours", OtherKey = "employeeID")]
public EntitySet<workDay> Hours
{
get { return this._hours; }
set { this._hours.Assign(value); }
}
[Column(IsPrimaryKey = true, IsDbGenerated = true)]
public Int32 employeeID { get; set; }
[Column]
public String firstName { get; set; }
[Column]
public String nickName { get; set; }
[Column]
public String lastName { get; set; }
[Column]
public String idNumber { get; set; }
}
這一切能夠完美的一個外鍵關係,我可以很容易地訪問來自Hours實體集的詳細記錄。我想知道是否可以根據某些標準自動過濾詳細信息。這樣做的原因是,我顯示一個「主/從」 datagridview的組合這些項目如下:
var employees = from emp in db.Employees
join empd in db.EmploymentDtls on emp.employeeID equals empd.employeeID
where empd.termination == null && empd.deleted == 0 && emp.deleted == 0
select emp;
dgvEmployees.DataSource = employees;
dgvHours.DataSource = employees;
dgvHours.DataMember = "Hours";
這使我沒有任何進一步的編碼,以顯示每個僱員的時間。我想達到相同的結果,但過濾到特定日期範圍的小時數,我想知道是否有任何方法可以應用默認過濾器,可以在細節加載到「詳細」dataGridView時應用。