Is it possible to ignore Where clause if Sessions.Current.AdminProductId is null? I would like to optimize code below into one line of code.
if (Sessions.Current.AdminProductId == null)
gvUsers.DataSource = DataAccess.Instance.Users;
else
gvUsers.DataSource = DataAccess.Instance.Users.Where(p => p.Orders.Any(o => o.ProductId == Sessions.Current.AdminProductId));
You just need to add the null check in the where clause like this: