'EF Core Property B should be NOT ISNULL(A)

I am using EF Core 6 and have the following question.

In my EF model "MyModel", I have a property.

public byte[] Thumbnail { get; set; }

These thumbnails can have some MB of data. So, I don't load them at the beginning. I now want an additional EF property in "MyModel".

// Should be sql equivalent NOT ISNULL(Thumbnail)
public bool HasThumbnail { get; set; }

That's needed because

// means not loaded yet OR no data at all
if(myModel.Thumbnail == null)
{
}

I know, that I can achieve this by using

context.MyModel.Select(...)

and map my HasThumbnail property in code.

But is there a way to tell the EF ModelBuilder this behaviour so that it works on the fly?



Sources

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

Source: Stack Overflow

Solution Source