Storing a complex detached object graph in EF6

后端 未结 1 947
故里飘歌
故里飘歌 2020-12-20 18:14

I have the current scenario:

I\'m using EF6 Code first, and have created a data-model something like this:

public class MainObject{
  ..some properti         


        
相关标签:
1条回答
  • 2020-12-20 19:04

    I ended up using GraphDiff to solve this for me, and it works just great! This really should be built into EF, but untill it does, this is a great substitute.

    To solve the example given in my question above, this will make sure that the detached graph gets saved properly (given I have a MainObject I want to save called main):

    context.UpdateGraph(main, map =>map
      .AssociatedCollection( m => m.SubObjects, with => with
        .AssociatedCollection( s => s.SubSubObjects)
      )
    );
    
    context.SaveChanges();
    
    0 讨论(0)
提交回复
热议问题