Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net C#如何在foreach中返回多个查询_Asp.net_Visual Studio_Linq_C# 4.0 - Fatal编程技术网

Asp.net C#如何在foreach中返回多个查询

Asp.net C#如何在foreach中返回多个查询,asp.net,visual-studio,linq,c#-4.0,Asp.net,Visual Studio,Linq,C# 4.0,因为目前我好像无法检索到 public IQueryable<Issue> commodityMatch_GetData(){ string userName = HttpContext.Current.User.Identity.Name; Context db = new Context(); IQueryable<Issue> query = db.Issues; //currentl

因为目前我好像无法检索到

        public IQueryable<Issue> commodityMatch_GetData(){

        string userName = HttpContext.Current.User.Identity.Name;
        Context db = new Context();
        IQueryable<Issue> query = db.Issues;
        //currently is filter by commodity and product line
        //looking on how to only filter by commodity

        var x = from r in db.Records
                where r.Username1 == userName
                select r.CommodityID;



        System.Diagnostics.Debug.WriteLine("Im fucking here");
        foreach(int s in x)
        {

            //s got 17 and 18
            System.Diagnostics.Debug.WriteLine(s);
            query = query.Where(p => p.CommodityID == s);
            //how to run mutiple time and return multiple times?
            //return mean end

        }


        return query;
        }

如果此处返回查询,则仅显示商品17的问题,而未显示商品18的问题。

尝试将问题加入到单个LINQ查询的记录中:

var x = from r in db.Records
        join i in db.Issues
        on r.CommodityID == iCommodityID
        where r.Username1 == userName
        select i;

return x;

请更新问题以显示完整功能。请使用完整功能更新问题。对于由此带来的不便,我深表歉意。谢谢您的帮助。它对我遇到的问题很有效。顺便问一下,我可以知道这个解决方案和我试图解决的方法有什么区别吗?@SadLife-在您最初的解决方案中,您正在循环处理您的db.Issues,但在第一个问题之后返回(退出)。在第二个解决方案中,您将在循环的每个迭代中替换
query
变量?希望了解更多。非常感谢。
var x = from r in db.Records
        join i in db.Issues
        on r.CommodityID == iCommodityID
        where r.Username1 == userName
        select i;

return x;