title: Passing object through ObjectDataSource Asp.net Error
body: <p>I'm working on a school project and I'm running into an error that has stumped me. I'm using entity framework, repository pattern, and object data source. The error I'm getting happens when I'm trying to insert a productvariant using the product ID foreign key(which is a urlparameter). </p>
  
  <p><strong>Error</strong></p>
  
  <p>ObjectDataSource 'ProductVariantObjectDataSource' could not find a non-generic method 'InsertProductVariantByProductId' that takes parameters of type 'FV_ProductVariant'. </p>
  
  <p><strong>Link to image</strong></p>
  
  <p><a href="http://i.stack.imgur.com/fJeR1.png" rel="nofollow">http://i.stack.imgur.com/fJeR1.png</a></p>
  
  <p><strong>Stack Trace:</strong></p>
  
  <p>[InvalidOperationException: ObjectDataSource 'ProductVariantObjectDataSource' could not find a non-generic method 'InsertProductVariantByProductId' that takes parameters of type 'FV_ProductVariant'.]
     System.Web.UI.WebControls.ObjectDataSourceView.GetResolvedMethodData(Type type, String methodName, Type dataObjectType, Object oldDataObject, Object newDataObject, DataSourceOperation operation) +1355789
     System.Web.UI.WebControls.ObjectDataSourceView.ExecuteInsert(IDictionary values) +339
     System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +89
     System.Web.UI.WebControls.DetailsView.HandleInsert(String commandArg, Boolean causesValidation) +379
     System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +574
     System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e) +95
     System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
     System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e) +112
     System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
     System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +125
     System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +169
     System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +9
     System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
     System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +176
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563</p>
  
  <p><strong>The object datasource within the aspx page</strong></p>
  
  <pre><code>    &lt;asp:ObjectDataSource ID="ProductVariantObjectDataSource" runat="server" 
      DataObjectTypeName="FV_ProductVariant" InsertMethod="InsertProductVariantByProductId" 
      SelectMethod="GetProductVariantByProductId" TypeName="ProductBL"&gt;
      &lt;InsertParameters&gt;
          &lt;asp:Parameter Name="productVariant" Type="Object" /&gt;
          &lt;asp:QueryStringParameter Name="productId" QueryStringField="ProductId" 
              Type="Int32" /&gt;
      &lt;/InsertParameters&gt;
      &lt;SelectParameters&gt;
          &lt;asp:QueryStringParameter Name="productId" QueryStringField="ProductId" 
              Type="Int32" /&gt;
      &lt;/SelectParameters&gt;
  &lt;/asp:ObjectDataSource&gt;
  </code></pre>
  
  <p><strong>ProductBL where the ObjectDataSource is inserting with</strong></p>
  
  <pre><code>    public void InsertProductVariantByProductId(FV_ProductVariant productVariant, int productId)
  {
      try
      {
          productRepository.InsertProductVariantByProductId(productVariant, productId);
      }
      catch (Exception ex)
      {
          throw ex;
      }
  }
  </code></pre>
  
  <p><strong>The IRepository</strong></p>
  
  <pre><code>    void InsertProductVariantByProductId(FV_ProductVariant productVariant, int ProductId);
  </code></pre>
  
  <p><strong>The actual Repository</strong></p>
  
  <pre><code>    public void InsertProductVariantByProductId(FV_ProductVariant productVariant, int productId)
  {
      try
      {
          productVariant.ProductVariantId = GenerateProductVariantID();
          productVariant.ProductId = productId;
          context.FV_ProductVariant.AddObject(productVariant);
          context.SaveChanges();
      }
      catch (Exception ex)
      {
          throw ex;
      }
  }
  </code></pre>