title: Entity Framework - inserting new entity via objectcontext does not use existing entity properties
body: <p>I have an insert method on my repository like so:</p>
  
  <pre><code>public T Insert(T entity) 
  {
      _ctx.AddObject(EntityName, entity);
      _ctx.SaveChanges();
      return entity;
  }
  </code></pre>
  
  <p>If I execute the below code, the values assigned to my entity do not propagate to the SQL that is executed.</p>
  
  <pre><code>Category c = new Category();
  c.Name = CLEARANCE;
  c = categoryManager.Insert(c);
  </code></pre>
  
  <p>The SQL should be something like </p>
  
  <pre><code>INSERT INTO Category(Name) VALUES('Clearance')
  </code></pre>
  
  <p>Instead, the following SQL is being executed</p>
  
  <pre><code>insert [dbo].[Category]([Name])
  values (null)
  select [Id]
  from [dbo].[Category]
  where @@ROWCOUNT &gt; 0 and [Id] = scope_identity()
  </code></pre>
  
  <p>I debugged the code right down to the AddObject method and verified that the Name property was set on the entity, but it doesn't reflect that in the SQL.</p>
  
  <p>Can you see anything wrong with what I'm doing?</p>
  
  <hr>
  
  <p><strong>Updated with mapping xml</strong></p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"&gt;
    &lt;!-- EF Runtime content --&gt;
    &lt;edmx:Runtime&gt;
      &lt;!-- SSDL content --&gt;
      &lt;edmx:StorageModels&gt;
        &lt;Schema Namespace="ProductCatalogModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl"&gt;
          &lt;EntityContainer Name="ProductCatalogModelStoreContainer"&gt;
            &lt;EntitySet Name="Category" EntityType="ProductCatalogModel.Store.Category" store:Type="Tables" Schema="dbo" /&gt;
            &lt;EntitySet Name="Product" EntityType="ProductCatalogModel.Store.Product" store:Type="Tables" Schema="dbo" /&gt;
            &lt;AssociationSet Name="FK_Product_Category" Association="ProductCatalogModel.Store.FK_Product_Category"&gt;
              &lt;End Role="Category" EntitySet="Category" /&gt;
              &lt;End Role="Product" EntitySet="Product" /&gt;
            &lt;/AssociationSet&gt;
          &lt;/EntityContainer&gt;
          &lt;EntityType Name="Category"&gt;
            &lt;Key&gt;
              &lt;PropertyRef Name="Id" /&gt;
            &lt;/Key&gt;
            &lt;Property Name="Id" Type="int" Nullable="false" StoreGeneratedPattern="Identity" /&gt;
            &lt;Property Name="Name" Type="varchar" Nullable="false" MaxLength="50" /&gt;
          &lt;/EntityType&gt;
          &lt;EntityType Name="Product"&gt;
            &lt;Key&gt;
              &lt;PropertyRef Name="Id" /&gt;
            &lt;/Key&gt;
            &lt;Property Name="Id" Type="int" Nullable="false" StoreGeneratedPattern="Identity" /&gt;
            &lt;Property Name="Name" Type="varchar" Nullable="false" MaxLength="50" /&gt;
            &lt;Property Name="CategoryId" Type="int" Nullable="false" /&gt;
          &lt;/EntityType&gt;
          &lt;Association Name="FK_Product_Category"&gt;
            &lt;End Role="Category" Type="ProductCatalogModel.Store.Category" Multiplicity="1" /&gt;
            &lt;End Role="Product" Type="ProductCatalogModel.Store.Product" Multiplicity="*" /&gt;
            &lt;ReferentialConstraint&gt;
              &lt;Principal Role="Category"&gt;
                &lt;PropertyRef Name="Id" /&gt;
              &lt;/Principal&gt;
              &lt;Dependent Role="Product"&gt;
                &lt;PropertyRef Name="CategoryId" /&gt;
              &lt;/Dependent&gt;
            &lt;/ReferentialConstraint&gt;
          &lt;/Association&gt;
        &lt;/Schema&gt;
      &lt;/edmx:StorageModels&gt;
      &lt;!-- CSDL content --&gt;
      &lt;edmx:ConceptualModels&gt;
        &lt;Schema Namespace="ProductCatalogModel" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm"&gt;
          &lt;EntityContainer Name="ProductCatalogEntities"&gt;
            &lt;EntitySet Name="Category" EntityType="ProductCatalogModel.Category" /&gt;
            &lt;EntitySet Name="Product" EntityType="ProductCatalogModel.Product" /&gt;
            &lt;AssociationSet Name="FK_Product_Category" Association="ProductCatalogModel.FK_Product_Category"&gt;
              &lt;End Role="Category" EntitySet="Category" /&gt;
              &lt;End Role="Product" EntitySet="Product" /&gt;
            &lt;/AssociationSet&gt;
            &lt;/EntityContainer&gt;
          &lt;EntityType Name="Category"&gt;
            &lt;Key&gt;
              &lt;PropertyRef Name="Id" /&gt;
            &lt;/Key&gt;
            &lt;Property Name="Id" Type="Int32" Nullable="false" /&gt;
            &lt;Property Name="Name" Type="String" Nullable="false" MaxLength="50" Unicode="false" FixedLength="false" /&gt;
            &lt;NavigationProperty Name="Product" Relationship="ProductCatalogModel.FK_Product_Category" FromRole="Category" ToRole="Product" /&gt;
          &lt;/EntityType&gt;
          &lt;EntityType Name="Product" Abstract="false"&gt;
            &lt;Key&gt;
              &lt;PropertyRef Name="Id" /&gt;
            &lt;/Key&gt;
            &lt;Property Name="Id" Type="Int32" Nullable="false" /&gt;
            &lt;Property Name="Name" Type="String" Nullable="false" MaxLength="50" Unicode="false" FixedLength="false" /&gt;
            &lt;NavigationProperty Name="Category" Relationship="ProductCatalogModel.FK_Product_Category" FromRole="Product" ToRole="Category" /&gt;
          &lt;/EntityType&gt;
          &lt;Association Name="FK_Product_Category"&gt;
            &lt;End Role="Category" Type="ProductCatalogModel.Category" Multiplicity="1" /&gt;
            &lt;End Role="Product" Type="ProductCatalogModel.Product" Multiplicity="*" /&gt;
          &lt;/Association&gt;
          &lt;/Schema&gt;
      &lt;/edmx:ConceptualModels&gt;
      &lt;!-- C-S mapping content --&gt;
      &lt;edmx:Mappings&gt;
        &lt;Mapping Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS"&gt;
          &lt;EntityContainerMapping StorageEntityContainer="ProductCatalogModelStoreContainer" CdmEntityContainer="ProductCatalogEntities"&gt;
            &lt;EntitySetMapping Name="Category"&gt;
              &lt;EntityTypeMapping TypeName="IsTypeOf(ProductCatalogModel.Category)"&gt;
                &lt;MappingFragment StoreEntitySet="Category"&gt;
                  &lt;ScalarProperty Name="Id" ColumnName="Id" /&gt;
                  &lt;ScalarProperty Name="Name" ColumnName="Name" /&gt;
                &lt;/MappingFragment&gt;
              &lt;/EntityTypeMapping&gt;
            &lt;/EntitySetMapping&gt;
            &lt;EntitySetMapping Name="Product"&gt;
              &lt;EntityTypeMapping TypeName="IsTypeOf(ProductCatalogModel.Product)"&gt;
                &lt;MappingFragment StoreEntitySet="Product"&gt;
                  &lt;ScalarProperty Name="Id" ColumnName="Id" /&gt;
                  &lt;ScalarProperty Name="Name" ColumnName="Name" /&gt;
                &lt;/MappingFragment&gt;
              &lt;/EntityTypeMapping&gt;
              &lt;/EntitySetMapping&gt;
            &lt;AssociationSetMapping Name="FK_Product_Category" TypeName="ProductCatalogModel.FK_Product_Category" StoreEntitySet="Product"&gt;
              &lt;EndProperty Name="Category"&gt;
                &lt;ScalarProperty Name="Id" ColumnName="CategoryId" /&gt;
              &lt;/EndProperty&gt;
              &lt;EndProperty Name="Product"&gt;
                &lt;ScalarProperty Name="Id" ColumnName="Id" /&gt;
              &lt;/EndProperty&gt;
            &lt;/AssociationSetMapping&gt;
            &lt;/EntityContainerMapping&gt;
        &lt;/Mapping&gt;
      &lt;/edmx:Mappings&gt;
    &lt;/edmx:Runtime&gt;
    &lt;!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) --&gt;
    &lt;edmx:Designer xmlns="http://schemas.microsoft.com/ado/2007/06/edmx"&gt;
      &lt;edmx:Connection&gt;
        &lt;DesignerInfoPropertySet&gt;
          &lt;DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" /&gt;
        &lt;/DesignerInfoPropertySet&gt;
      &lt;/edmx:Connection&gt;
      &lt;edmx:Options&gt;
        &lt;DesignerInfoPropertySet&gt;
          &lt;DesignerProperty Name="ValidateOnBuild" Value="true" /&gt;
        &lt;/DesignerInfoPropertySet&gt;
      &lt;/edmx:Options&gt;
      &lt;!-- Diagram content (shape and connector positions) --&gt;
      &lt;edmx:Diagrams&gt;
        &lt;Diagram Name="Model"&gt;
          &lt;EntityTypeShape EntityType="ProductCatalogModel.Category" Width="1.5" PointX="0.75" PointY="0.875" Height="1.427958984375" IsExpanded="true" /&gt;
          &lt;EntityTypeShape EntityType="ProductCatalogModel.Product" Width="1.5" PointX="3" PointY="0.875" Height="1.427958984375" IsExpanded="true" /&gt;
          &lt;AssociationConnector Association="ProductCatalogModel.FK_Product_Category" ManuallyRouted="false"&gt;
            &lt;ConnectorPoint PointX="2.25" PointY="1.5889794921875" /&gt;
            &lt;ConnectorPoint PointX="3" PointY="1.5889794921875" /&gt;&lt;/AssociationConnector&gt;
          &lt;/Diagram&gt;&lt;/edmx:Diagrams&gt;
    &lt;/edmx:Designer&gt;
  &lt;/edmx:Edmx&gt;
  </code></pre>