简体   繁体   English

子查询在C#foreach循环中返回了多个值

[英]Subquery returned more than 1 value in C# foreach loop

I am getting the above error in a foreach statement in some C# code that I have "inherited" it essentially reads csv files and makes changes in a database depending on the info in the csv. 我在“继承”某些C#代码的foreach语句中遇到上述错误,它实际上是读取csv文件并根据csv中的信息在数据库中进行更改。

The code is as below: 代码如下:

 using (var ctx = new MyEntities())
        {
            foreach (var notification in despatches)
            {
                var componentCheck = ctx.DespatchLineComponentCheck(notification.ProductCode).ToList();

The despatches, gets a list of custom DespatchLines type, which are essentially a model. 调度将获取自定义DespatchLines类型的列表,该类型本质上是一个模型。

As far as I can tell the code calls a stored procedure that in turn calls a view. 据我所知,代码调用了存储过程,而存储过程又调用了视图。

The stored procedure and the view execute no problems which makes me think that it's the C# code, but I am a little unsure. 存储过程和视图不会执行任何问题,这使我认为它是C#代码,但是我不确定。

Any help is appreciated. 任何帮助表示赞赏。

Thanks for the comments from @Leonidas199x and @Jacob H. In the end it was an SQL error, with a stored procedure calling on a table that returned multiple results when it should have only given one. 感谢@ Leonidas199x和@Jacob H的评论。最后,这是一个SQL错误,存储过程在一个表上调用,该表在只给出一个结果时将返回多个结果。

A user here had put data in that wasn't unique and had caused the error. 这里的用户放置的数据不是唯一的,并导致了错误。

Thanks for the help! 谢谢您的帮助!

暂无
暂无

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

相关问题 子查询返回了多个值。.查询C#异常 - Subquery returned more than 1 value.. query C# exception C#返回错误“子查询返回的值大于1”,但这应该可以 - C# returns error 'Subquery returned more than 1 value' but that should be ok SQLCLR程序集上的“子查询返回了多个值” - “Subquery returned more than 1 value” on SQLCLR Assembly SqlException因为子查询返回了多个值 - SqlException because Subquery returned more than 1 value SQL Server 中的子查询返回了 1 个以上的值 - A subquery in SQL Server returned more than 1 value 子查询返回了 1 个以上的值。 当子查询跟随 =、!=、&lt;、&lt;=、&gt;、&gt;= 时,这是不允许的 - Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= 如何解决子查询返回超过1个值的错误 - How to resolve Subquery returned more than 1 value error 发生此错误的原因:子查询返回了多个值 - Why this error occurs: Subquery returned more than 1 value .NET MVC - C# foreach 循环在 IE11 中不起作用。 仅返回循环中的最后一个值 - .NET MVC - C# foreach loop not working in IE11. Only last value in loop being returned .NET SQL via Petapoco &quot;子查询返回了 1 个以上的值。当子查询跟随 =、!=、&lt;、&lt;=、&gt;、&gt;= 时,这是不允许的 - .NET SQL via Petapoco "Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >="
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM