views:

106

answers:

0

To use by the easiest way Entity Framework, I use partial class to add Foreign Key on most important Entities Model.

For example, I have an Entity "CONTACT" which have "TITLE", "FUNCTION" and others. When I update a CONTACT, with this code, Foreign Key are automatically updated :

public int? TitId
{
    get
    {
        if (this.TITLE_TIT != null)
            return TITLE_TIT.TIT_ID;
        return new Nullable<int>();
    }
    set
    {
        this.TITLE_TITReference.EntityKey = new System.Data.EntityKey("Entities.TITLE_TIT", "TIT_ID", value);
    }
}

But I have a join with ACTIVITY, that can have many CONTACT, and I don't know how to update EntityKey on setters.

public IEnumerable<EntityKeyMember> ActId
{
    //Maybe Working ?
    get
    {
        List<EntityKeyMember> lst = new List<EntityKeyMember>();
        if (this.ACT_CON2 != null)
        {                    
            foreach (ACT_CON2 id in this.ACT_CON2.ToList())
            {
                EntityKeyMember key = new EntityKeyMember(id.CON_ID.ToString(),id.ACT_ID);
                lst.Add(key);
            }
        }
        return lst;
    }
    //Not Working !
    set
    {    
        this.ACT_CON2.EntityKey = new System.Data.EntityKey("Entities.ACT_CON2", value);
    }
}

How set many EntityKey ?

Thank you.