使用LINQ,如何选择并仅返回第一个关联的子项?
我有:
[table: Report]
GeneratedDate
PerformanceMetric 1 -----> N [table PerformanceMetric]
Bios Timestamp
... X
Y
..... (there is a good dozen other fields)
目前,我的工作内容包括:
Report = _ctx.Reports.SingleorDefault(rpt => rpt.bios == mySerial);
这将返回与所有PerformanceMetric相关联的报告。我想只返回第一个PerformanceMetric的出现。
LINQ是否提供了内置方法来实现此功能?
编辑:实际上,我正在寻找报告,但是PerformanceMetric应该仅包含第一个元素。(Report.PerformanceMetrics.Count <= 1) 抱歉没有表达清楚..