Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 761277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:49:07+00:00 2026-05-14T15:49:07+00:00

My controller calls a repository class method on insert, [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create([Bind(Exclude =

  • 0

My controller calls a repository class method on insert,

 [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create([Bind(Exclude = "Id")]FormCollection collection)
        {
            try
            {
                MaterialsObj materialsObj = new MaterialsObj();
                materialsObj.Mat_Name = collection["Mat_Name"];
                materialsObj.Mes_Id = Convert.ToInt64(collection["MeasurementType"]);
                materialsObj.Mes_Name = collection["Mat_Type"];
                materialsObj.CreatedDate = System.DateTime.Now;
                materialsObj.CreatedBy = Convert.ToInt64(1);
                materialsObj.IsDeleted = Convert.ToInt64(1);
                consRepository.createMaterials(materialsObj);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

and my repository class has this,

public MaterialsObj createMaterials(MaterialsObj materialsObj)
{
    db.Materials.InsertOnSubmit(materialsObj);
    return materialsObj;
}

But when i compile this i get The best overloaded method match for 'System.Data.Linq.Table<CrMVC.Models.Material>.InsertOnSubmit(CrMVC.Models.Material)' has some invalid arguments…
cannot convert from 'CrMVC.BusinessObjects.MaterialsObj' to 'CrMVC.Models.Material'..

am i missing something?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:49:08+00:00Added an answer on May 14, 2026 at 3:49 pm

    The object you pass to InsertOnSubmit has to be one of your LINQ-to-SQL Classes.

    In this case, you’re trying to insert an Object of a type that LINQ-to-SQL has no idea about (one of your business objects, not a LINQ-to-SQL type).

    There are several ways to overcome this. Once is to convert the business object to the appropriate LINQ-to-SQL class in your Repository. The other is to create an implicit cast between the two and let .NET handle the rest.

    Repository Cast Code

    public MaterialsObj createMaterials(MaterialsObj materialsObj)
    {
        CrMVC.Models.Material mat = new CrMVC.Models.Material();
    
        // copy properties to the Materials object from materialsObj
        db.Materials.InsertOnSubmit(mat);
    
        materialsObject.IdField = mat.IdField;
    
        return materialsObj;
    }
    

    Implicit Cast Code (method added to the Business Object class)

    public static implicit operator CrMVC.Models.Material
        (CrMVC.BusinessObjects.MaterialsObj)
    {
        // Add conversion code here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a controller action which renders a partial view: public ActionResult Details(int id)
i wish to create a repository pattern but with a WCF Rest Service which
We are using JPA entity beans as our model for Spring MVC controller on
My application I have an application design that looks like this: web application layer
Here's the scenario: ASP.NET MVC2 Web Application Entity Framework 4 (Pure POCO's, Custom Data
I've been working with S#arp Architecture but this can probably be applied to any
Using MVC and trying to use dependency injection for controllers, but when I try
I have a wizard in my asp.net MVC application which is built upon this
When working on multiple (open source) projects, multiple version controll systems start to be
My usual way of working on web development is to split the project into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.