In addition to SiteCore's solid solution here, I'd like to add that I think it's a good idea when you have complex, nested, Linq queries, and some of the values you are "lining up" to extract and manipulate might be null/undefined ... and you don't want to deal with those values ...
Let me illustrate:
int? total = null;
if (asset != null && asset.portfolioInfo != null)
{
total =
asset.portfolioInfo
.Where(pi => pi != null)
.SelectMany(acc => acc.accounts)
.Where(act => act.initialValue != null)
.Sum(val => (int?) val.initialValue);
}
Think about a large complex dataset you want to query against; perhaps excluding a large number of instances/records would help reduce the "cost of using Linq ?