我正在努力解决以下问题.
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; } }
我正在尝试如下查询,试图从比赛和活动中获得结果信息的季节“2013”.如果有人知道,pleSAE建议.
if (year.HasValue) { model = model.Where(x => x. ?? }
解决方法
你可以做:
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 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();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。