I am looking to do a linq query with Dynamic Linq library, but I am trying to select a property which is an IEnumerable<T> collection which throws an exception when calling the Sum() function in dynamic linq. I am wondering if I could say something like this:
queryable.Select("new (Sum(collection == null ? 0 : collection.Count) as Total)")
because
Select("new (Sum(np(Contestants.Count, 0)) as Total)")
returns a null reference exception
The
np(NullPropagation) is used correctly, butSumcan only be used if you group. (Just like normal Linq)A possible working code example could be:
Debug result: