开发者

entity framework inserting a many to many relationship across multiple contexts

开发者 https://www.devze.com 2023-02-01 16:55 出处:网络
I have an Events table and a PaymentTypes table which are linked by Events_PaymentTypes join table. EF allows me to add an entry into the join table by doing Event.PaymentTypes.Add(PaymentType).Howeve

I have an Events table and a PaymentTypes table which are linked by Events_PaymentTypes join table. EF allows me to add an entry into the join table by doing Event.PaymentTypes.Add(PaymentType). However, I'm getting the PaymentTypes from one contex开发者_如何学Ct and doing the add operation in another context. If I detach the PaymentType first, it creates a new record in the PaymentTypes table, which is not what I want. How can I get around this?


figured it out. I wasn't attaching it to the other context before adding it.

0

精彩评论

暂无评论...
验证码 换一张
取 消