title: MVC3 DbContext Get New Model's ID After Save?
body: <p>I have a model Product with a 1:n relationship with model Product_Tag.  I also have a model Tag has a 1:n relationship with Product_Tag.  </p>
  
  <pre><code>class Product{
    int ID {get;set;}
    public virtual ICollection&lt;Product_Tag&gt; productTag {get;set;}
  }
  
  class Tag {
    int ID {get;set;}
    public virtual ICollection&lt;Product_Tag&gt; productTag {get;set;}
  
  }
  
  class Product_Tag {
    int ID {get;set;}
    int ProductID{get;set;}
    int TagID {get;set;}
    public virtual Product product {get;set;}
    public virtual Tag tag {get;set;}
  }
  </code></pre>
  
  <p>When saving a new Product, I want to be able to save any associations to Tags in Product_Tags.  Product_Tag requires a PRoductID and a TagID.  I have the TagID's available at save time, but the ProductID will come from thew newly-created Product.  How to get the newly-created Product's ID immediately after saving the new Product?</p>
  
  <p>Alternatively, is there a way to just save the Product model with its productTags having only TagID's and get DbContext to fill in the ProductID for me?</p>