Update one-to-many EntityKey using Foreign Key

Posted by User.Anonymous on Stack Overflow See other posts from Stack Overflow or by User.Anonymous
Published on 2010-04-12T15:21:36Z Indexed on 2010/04/12 15:23 UTC
Read the original article Hit count: 339

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
    {
        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;
        }
        set
        {    
            this.ACT_CON2.EntityKey = new System.Data.EntityKey("Entities.ACT_CON2", value);
        }
    }

How set many EntityKey ?

Thank you.

© Stack Overflow or respective owner

Related posts about c#

Related posts about entity-framework