EF programmatically embed many of the many
2 answers
If you want to use your own structure, you need to get instances of Activity and Contact and just set the appropriate properties for the new object.
var newActivityContact = new ActivityContact();// m_Entities.CreateActivityContact(0);
newActivityContact.Activity = activityRepository.GetById(activityId);
newActivityContact.Contact = contactRepository.GetById(contactId);
m_Entities.AddToActivityContact(newActivityContact);
m_Entities.SaveChanges();
0
a source to share
I think the best solution would be to get rid of the primary key, set up the combination of ActivityID and ContactID as PK, and then recreate the whole model in visual designer. Every object Activity
has a navigation property Contacts
, and everyone Contact
will Activities
. You will be able to add contacts to the action by calling:
activity.Contacts.Add(contact);
If you really need an additional ID, this will be trickier.
0
a source to share