I would like to use the Null-Conditional Operator to check the SubscriptionExpires property below.
public partial class Subscription
{
[Key]
public int SubscriptionId { get; set; }
public string SubscriberId { get; set; }
public DateTime? SubscriptionExpires { get; set; }
public virtual ICollection<ApplicationUser> Users { get; set; }
}
A subscription is returned by
var subscription = _customersContext.Subscriptions.Where(s => s.SubscriptionId == user.SubscriptionId).FirstOrDefault();
However if Subscription is null, Subscription?.SubscriptionExpires returns a null reference exception, so we are still left with the old
if (subscription != null)
How do I use the Null-Conditional Operator to read a property when the parent object can be null?