How do I add a reference to another existing entity using code-first framework without first pulling the existing entity from the database -


I am trying to add an existing product to the auction, but unable to do this without dragging the product before Database

This code works, but how do I go about providing the productive and then saving the auction

  var product = new product () {// Known Existing Product ID ProductId = 1}; Var Auction = New Auction {BuyItNowPrice = 10. Product = Product, ... ...}; (Var db = New DataContext ()) using {var product = db.Products.Find (Auction.product.product ID); auction. Product = product; Db.Auctions.Add (Auction); Db.SaveChanges (); }    

include scalar property ProductId in the // other proerties}

then

  auction. Producer = 1; db.Auctions.Add (auction); db.SaveChanges ();    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -