简体   繁体   English

LINQ说insertonsubmit的参数无效

[英]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#. 我似乎在使用C#中的LINQ将数据插入到SQL Server 08R2中的表中时遇到了这个问题。 No matter what I've tried I keep getting an error with INSERTONSUBMIT() . 无论我尝试过什么,我都会在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. void Table.InsertOnSubmit(UNITBC entity)将处于挂起插入状态的实体添加到此System.Data.Linq.Table。 Error: The best overloaded method match for 'System.Data.Linq.Table.InsertOnSubmit(AS5553.UNITBC)' has some invalid arguments 错误:'System.Data.Linq.Table.InsertOnSubmit(AS5553.UNITBC)'的最佳重载方法匹配有一些无效的参数

The container I used to hold the variables matches the table datatypes. 我用来保存变量的容器与表数据类型匹配。 ( string to varchar(64) ) I know I need the unit.SubmitChanges(); string to varchar(64) )我知道我需要unit.SubmitChanges(); next but it doesn't matter as I can't get passed the INSERTONSUBMIT() point. 接下来但没关系,因为我无法通过INSERTONSUBMIT()点。 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... 这是所要求的unitnotest类......

    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 . 看来, EntityObject类型的unitnotest从不同EntityObject的的ObjectSet类型的UNITBCs

Means you are trying to insert the wrong object. 意味着您正在尝试插入错误的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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