'Linq query: how do I default a null value

I have a linq query originating from an entity Framework model. I'm having problems with nulls which won't materialize and I can't seem to find a solution for.

Here's partial code showing the Select:

.Select(x => new
{
    x.PageConfig.RouteName,
    x.RouteValues,
    x.PageConfig.PhysicalFile,
    MetaLastModified = x.PageMeta.LastModified,
    ImageLastModified = x.FeaturedImage.LastModified,
    SitemapFrequency = x.PageConfig.Sitemap.Frequency,
    SitemapPriority = x.PageConfig.PageType.Priority
})

The issue I'm having is that x.FeaturedImage can be a null entry, so LastModified can't be materialized and is throwing up the problem.

I've tried a few things, including this: x.FeaturedImage?.LastModified ?? DateTime.MinValue, but can't get it to work.

How do I get round this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source