The query below should specify records that either have the corresponding identifier specified in ownerGroupIds or the corresponding ownerUserId . However ownerUserId is null, I want this part of the request to be ignored.
public static int NumberUnderReview(int? ownerUserId, List<int> ownerGroupIds)
{
return ( from c in db.Contacts
where
c.Active == true
&&
c.LastReviewedOn <= DateTime.Now.AddDays(-365)
&&
(
!ownerUserId.HasValue ||
c.OwnerUserId.Value == ownerUserId.Value
)
&&
(
ownerGroupIds.Count == 0 ||
ownerGroupIds.Contains( c.OwnerGroupId.Value )
)
select c ).Count();
}
However, when null is passed for ownerUserId , I get the following error:Nullable object must have a value.
I get a tingling sensation, may I have to use the lambda expression in this case?
source
share