Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Entity Framework 4.0 Beta: Updating Reference Keys

Entity Framework 4.0 Beta: Updating Reference Keys

Scheduled Pinned Locked Moved LINQ
asp-netcsharpbeta-testingarchitecturetutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rookian
    wrote on last edited by
    #1

    Hi! I created the following model: EF Model[^] Now I have ASP.NET MVC and want to edit an existing product. When I save the updated product only product proprties are saved instead of the other references too. So the foreign keys of product didn't change. Here is my Code to update the product:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Create(Product product, Unit unit, Packing packing, Shelf shelf, Bestbefore bestbefore )
    {
    product.BestbeforeReference.EntityKey =
    new System.Data.EntityKey("WebDBEntities.Bestbefore", "BestbeforeID", bestbefore.BestbeforeID);

            product.PackingReference.EntityKey =
                new System.Data.EntityKey("WebDBEntities.Packing", "PackingID", packing.PackingID);
    
            product.ShelfReference.EntityKey =
                new System.Data.EntityKey("WebDBEntities.Shelf", "ShelfID", shelf.ShelfID);
    
            product.UnitReference.EntityKey =
                new System.Data.EntityKey("WebDBEntities.Unit", "UnitID", unit.UnitID);
            
            
    
            if (ModelState.IsValid)
            {            
                \_db.AddToProduct(product);
               
                \_db.SaveChanges();
                return RedirectToAction("ProductList");
            }
            
            return RedirectToAction("ProductList");
        } 
    

    Can someone explain me how to udate the foreign keys? :confused: Thanks in advance!

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups