[英]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.