CTP4에 대한 내 머리 속에 컴파일되므로 잘 알고 있어야합니다.
public void AddPersonToList(int id, int toAdd)
{
var mailList = new MailList { ID = id, ContactInformations = new List<ContactInformation>() };
this.db.MailLists.Attach(mailList);
var ci = new ContactInformation { ID = toAdd };
this.db.ContactInformations.Attach(ci);
this.db.ObjectStateManager.ChangeRelationshipState(mailList, ci, ml => ml.ContactInformations, System.Data.EntityState.Added);
}
지속되기 전에 SaveChanges를 호출해야합니다.
ID 만 있고 Statemanager로 작업하는 엔티티를 연결하면 EF에서 정말 잘 작동하며 성능면에서 멋진 솔루션을 만들 수 있습니다.