简体   繁体   中英

LINQ saying invalid arguments for insertonsubmit

I seem to be running into this issue with inserting data into a table in a SQL Server 08R2 using LINQ in C#. No matter what I've tried I keep getting an error with INSERTONSUBMIT() . Here is the code...

private void testUpdateUNITBC()
{
      using (unitDataContext unit = new unitDataContext())
      {
            unitnotest unitbc = new unitnotest();
                 unit.FBARCO = "1234";
                 unit.FUNITNO = "1234";
                 unit.FJOBNO = "I9999-0000";
                 unit.FBOXNO = "999";
                 unit.FOPNO = "999";

             unit.UNITBCs.InsertOnSubmit(unitbc); <--this is where I get the error
       };

The error reads

void Table.InsertOnSubmit(UNITBC entity) Adds an entity in a pending insert state to this System.Data.Linq.Table. Error: The best overloaded method match for 'System.Data.Linq.Table.InsertOnSubmit(AS5553.UNITBC)' has some invalid arguments

The container I used to hold the variables matches the table datatypes. ( string to varchar(64) ) I know I need the unit.SubmitChanges(); next but it doesn't matter as I can't get passed the INSERTONSUBMIT() point. Any help would be great as I've tried several things and spent the entire day working on this with research.

Update

Here is the unitnotest class as requested...

    public class unitnotest 
{ 
     public string FBARCO {get;set;}
     public string FUNITNO {get;set;}
     public string FJOBNO {get;set;}
     public string FBOXNO {get;set;}
     public string FOPNO {get;set;}
}

It seems that the EntityObject of type unitnotest is different from the EntityObject of the ObjectSet of type UNITBCs .

Means you are trying to insert the wrong object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM