I have a problem with inserting objects with an entity data model, and despite my best efforts to find the solution, I'm coming up short.
I have a database with lots of tables which refer to others. two of these tables are vendor and gl_account. a vendor may have zero or more gl_account objects associated with it. I want to create a vendor object and all of its gl_accounts in one go, but I keep getting foreign key constraint errors.
am I doing something horribly wrong? I don't want to call SaveChanges() after creating the vendor object, because then it can't be rolled back if something else goes wrong.Code:vendor myVendor = vendor.Createvendor(0); // the value for id_vendor gl_account glAccount = gl_account.Creategl_account(0); // the value for id_gl_account myVendor.gl_accounts.Add(glAccount); dbContext.SaveChanges();



LinkBack URL
About LinkBacks




