我是新的所有實體框架模型和數據綁定。 我創建了一個接口,並從db中的我的Candidate
表中生成了一個模型類。僅綁定接口屬性的數據
public interface ICandidate
{
String ID { get; set; }
string Name { get; set; }
string Mail { get; set; }
}
我創建了一個局部類到生成Candidate
模型,所以我將能夠實現ICandidate
接口而不改變任何生成的代碼。
public partial class Candidates : ICandidate
{
string ICandidate.ID
{
get { return this.PK; }
set { _PK = value; }
}
string ICandidate.Name
{
get{ return this._Name; }
set { _Name = value; }
}
string ICandidate.Mail
{
get { return this._Email; }
set { this._Email = value; }
}
}
當然,生成的類具有比接口更多的屬性(如IsDeleted字段,不需要接口)。
我想顯示在DataGridView
所有的數據庫的候選人。但我希望只有界面的屬性會顯示爲DataGridView
中的列。
- 有沒有辦法只綁定接口的屬性DataGridView?
- 在我的數據庫中有一個名爲Candidate_To_Company的表,其中包含以下列: PK,Candidate_FK,Company_FK,Insertion_Date 我想將此表綁定到DataGridView。但不是顯示Candidate_FK,我想從ICandidate顯示候選名稱。這可能嗎?