How to add existing collection of entities to existing entity without pulling first pulling existing entities from database using code-first framework -
I am trying to attach two existing and one new bid bid for the existing current auction, but without doing so Unable to pull the product from the database.
This code works, but I just have to go to the bid for providing the bid id and then save about the auction.
Db = new datacentex ()) // Existing auction auction = auction = db Down Search (1); Var bid 1 = DB Bids Search (1); Var bid 2 = DB Bids Search (2); Var bid 3 = new bid () {// new bid}; // Existing Auctions Bids Add (bid 1); // Existing Auctions Bids Add (bid 2); // new auction Bids Add (bid3); Db.SaveChanges (); } Edit - I also tried to do it properly, but found a referenced integrity problem: The following diagnostics:
{"Update in Store, Insert , Or delete an unexpected number of rows (0). The components can be modified or removed after the entities have been loaded. Refresh the Ostastate Manager entries. "}
Using (var db = new DataContextContext ()) {var blue = DB.Action Search (1); Var bid 1 = new bid () {BidId = 1}; Db.Bids.Attach (bid1); Auction.Bids.Add (bid1); Db.SaveChanges (); }
You can use DB to add known organizations in the context. Use of
(var db = new DataContext ()) // // Existing auction var auction = db.Auctions.Find (1); Var bid 1 = new bid () {BidId = 1}; Var bid2 = new bid () {BidId = 2}; Var bid 3 = new bid () {// new bid}; // Existing DB Atate (Beed 1); Auction.Bids.Add (bid1); // Existing DB.Actak (bid2); Auction.Bids.Add (bid2); // new auction Bids Add (bid3); Db.SaveChanges (); }
Comments
Post a Comment