简体   繁体   English

Linq to SQL-参数分配不正确/重复

[英]Linq to SQL - Parameters being assigned incorrectly/duplicates

I started with this question: ( how-to-compare-liststring-to-db-table-using-linq ). 我从这个问题开始:( 如何将列表字符串与使用linq的数据库表进行比较 )。 Using the solution offered there, it worked for my test with only 5 items in my list. 使用那里提供的解决方案,它只对我的列表中的5个项目起作用。

I'm having an issue with this now. 我现在对此有疑问。 I'm getting a SQL error saying "error near 0". 我收到一条SQL错误,提示“错误接近0”。

After using a LINQ to SQL visualizer, the problem is when Visual Studio is assigning the numbers in the list to the parameters. 使用LINQ to SQL可视化程序后,问题出在Visual Studio将列表中的数字分配给参数时。 It will assign the first 10 just fine. 它将分配前10个就好。

Once it hit the 11th, it jumps to the number at index 1 and assigns the same number 10 times to different params, but adding a last digit(0-9) to make each one unique. 一旦到达第11位,它就会跳到索引1处的数字,并将相同的数字分配给不同的参数10次,但添加最后一位数字(0-9)以使每个数字唯一。 It then moves to the number at index 2 and proceeds to assign that same number multiple times. 然后,它移动到索引2处的数字,并多次分配该数字。

It actually runs to the the end of the declared params, but I would imagine if there were 100 params declared it would continue. 它实际上运行到声明的参数的末尾,但是我可以想象是否有100个声明的参数将继续。

var custdata = from c in db.CUSTs  
           where tnbrs.Contains(c.NPA + c.NXX + c.LINE_NBR)
           select new { c.PON, c.PartnerID };

What is going on here? 这里发生了什么?

So apparently its the LINQ to SQL visualizer, procured from Scott Gu's blog, that has the problems with assigning the parameters correctly. 因此,显然是从Scott Gu的博客购买的LINQ to SQL可视化程序,存在正确分配参数的问题。

I used this class with the System.Diagnostics to log the the LINQ to SQL debug. 我用这个与System.Diagnostics程序所涉及的LINQ登录到SQL调试。

If you use the class above be sure to change the namespace to match the one declared in your project. 如果使用上面的类,请确保更改名称空间以匹配项目中声明的名称空间。

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

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