EF以编程方式插入多对多 [英] EF programmatically insert many to many
本文介绍了EF以编程方式插入多对多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个具有此结构ID PK的表和两个带有FK的列,例如ActivityID和ContactID。
我尝试以编程方式在这两个FK列中插入一些值。
我该怎么做,需要任何帮助。Tnx
I have table with this structure ID PK and two columns with FK for example ActivityID and ContactID. I try programmatically insert some value in this two FK columns. How can I do this, any help is appriciated.Tnx
推荐答案
如果您想使用自己的结构-
If you want to use your structure - you have to get instances of Activity and of Contact and just set corresponding properties on new entity.
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();
这篇关于EF以编程方式插入多对多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文