How do I add a reference to another existing entity using code-first framework without first pulling the existing entity from the database
问题 I'm trying to attach an existing product to an auction, but am unable to do so without first pulling the product from the database. This code works, but how would I go about just providing the productid and then saving the auction var product = new Product() { //Known existing product id ProductId = 1 }; var auction = new Auction { BuyItNowPrice = 10. Product = product, ... ... }; using (var db = new DataContext()) { var product = db.Products.Find(auction.Product.ProductId); auction.Product =