Bind data of interface properties only

Posted by nivpenso on Stack Overflow See other posts from Stack Overflow or by nivpenso
Published on 2012-12-05T22:55:12Z Indexed on 2012/12/05 23:03 UTC
Read the original article Hit count: 112

Filed under:
|
|

I am new in all the Entity Framework models and the data bindings. I created an interface and generated a model class from my Candidate table in the db.

public interface ICandidate
{
    String ID { get; set; }
    string Name { get; set; }
    string Mail { get; set; }
}

i created a partial class to the generated Candidate model so i will be able to implement the ICandidate interface without changing any generated code.

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; }
    }
}

Of course, the generated class has more properties than the interface has (Like IsDeleted field that is not necessary for the interface).

I want to display in a DataGridView all the candidates from the db. But I want that only the interface's properties will be shown as columns in the DataGridView.

  1. Is there a way bind only the interface's properties the the DataGridView?
  2. In my DB there is a table called Candidate_To_Company with these columns: PK, Candidate_FK, Company_FK, Insertion_Date I would like to bind this table to DataGridView. but instead of displaying Candidate_FK i would like to display the candidate name from ICandidate. Is this possible?

© Stack Overflow or respective owner

Related posts about c#

Related posts about entity-framework