Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.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
C# 带有两个where子句的Linq语句_C#_Asp.net Mvc 3_Linq_Lambda - Fatal编程技术网

C# 带有两个where子句的Linq语句

C# 带有两个where子句的Linq语句,c#,asp.net-mvc-3,linq,lambda,C#,Asp.net Mvc 3,Linq,Lambda,我正在努力解决以下问题 public class Competition { public int Id { get; set; } public string Name { get; set; } public IList<ResultInfo> ResultInfos { get; set; } public IList<Event> ChildEvents { get; set; } } public class Resu

我正在努力解决以下问题

    public class Competition
{
    public int Id { get; set; }
    public string Name { get; set; }
    public IList<ResultInfo> ResultInfos { get; set; }
    public IList<Event> ChildEvents { get; set; }
}


public class ResultInfo
{
    public int Id { get; set;}
    public string ResultInfoName { get; set;}
    public int Season { get; set; }
}

public class Event
{
    public int Id { get; set; }
    public string EventName { get; set; }
    public IList<ResultInfo> ResultInfos { get; set; } 
}
你可以做:

var competitions = new Competition(); // Populated competition class

var results = (from c in competitions
               from e in c.ChildEvents
               from ri in e.ResultInfos
               where ri.Season == 2013).ToList();
不清楚您为什么需要一个附加的
,where
,但是您可以扩展它并使用另一个子句,例如

where ri.Season == 2013 && EventName == "Event"
正如@von.v所指出的,您可以通过Competition类直接访问
ResultInfos
,因此您可以通过以下方式简化它:

   var results = (from c in competitions
                  from ri in c.ResultInfos
                  where ri.Season == 2013).ToList();

我不知道你想要什么?如果您希望比赛在2013年有结果信息,在2013年也有结果信息,您可以这样做:

model.Where(c => c.ChildEvents
                  .SelectMany(ce => ce.ResultInfos)
                  .Where(ri => ri.Season == 2013).Count() > 0
            &&
            c.ResultInfos.Where(ri => ri.Season == 2013).Count() > 0)
     .ToList();

但我不确定我是否了解您需要什么

然后您需要在直接存储在竞争对象中的ResultInfos的结果上进行连接。(竞赛结果在哪里(ri=>ri.赛季==2013));比赛中的
ResultInfo
s如何?还有一件事,建议将比赛中的
ResultInfo
s和比赛中的
ResultInfo
s结合起来如何。我想他可能需要这个,尽管我不确定他的问题到底是什么
model.Where(c => c.ChildEvents
                  .SelectMany(ce => ce.ResultInfos)
                  .Where(ri => ri.Season == 2013).Count() > 0
            &&
            c.ResultInfos.Where(ri => ri.Season == 2013).Count() > 0)
     .ToList();