I have a couple of linq queries that are causing an issue with nulls. I’m pretty sure there’s an easy answer but i can’t think what it is.
var IDs = _user.IsNotNull()
? _user.BookmarkedStores.Select(s => s.StoreId)
: null;
var stores = IDs.IsNotNull()
? StoreBL.FindActiveById(IDs).OrderBy(s => s.Name).ToList()
: null;
A null exception is thrown by the IQueryable.OrderBy because StoreBL.FindActiveById is null. A null return is valid as a store may be in the ID list but not active.
So I need to put a null check between them somehow.
Anyone advise as to if and how it can be done within the query itself?
I found a suitable answer.
FindActiveById() now returns Enumerable.Empty().AsQueryable() instead of null.