I have the following extension method:
public static decimal? GetValue(this Member member)
{
return member.Readings.SelectMany(r => r.Measurements).GetLatestValue();
}
GetLatestValue is another extension that only uses other LINQ extensions: OrderBy, Where, Select and First.
I'd expect this to perform a JOIN query. Instead, when I look in SQL Profiler, it is performing a separate query to select all measurements for each reading.
I understand from this and this question that I could get a JOIN if I passed in the database context and used that, however this is not an option for me.
What is happening here? Why is the Readings property an ICollection, not an IQueryable? How can I get a single query here, without having to change the extension methods signature?