best practise/way for master detail / multi table Insert in Entity Framework

前端 未结 2 721
被撕碎了的回忆
被撕碎了的回忆 2020-12-16 23:49

My table structure is this

Orders
------ 
Id int identity
OrderDate smalldatetime
OrderStatusid tinyint

Products
--------
Id int identity
Name varchar(50)

         


        
2条回答
  •  既然无缘
    2020-12-17 00:25

    Another approach would be to use Stub Objects rather than EntityKeys i.e.

    var product = new Product {ID = 2};
    ctx.AttachTo("Products", product);
    ode.Product = product;
    

    etc. As an added bonus this code will work with POCO objects too in the future.

    See this blog post for more information on that technique.

提交回复
热议问题