When I run this projection, the count is equal to the amount of People in my database:
int peopleProjectionCount = _db.People.Count();
However when I run this projection and get the count, what I get is a count of only the records where TitleType and SuffixType are not null.
int peopleProjectionCount = _db.People
.Select(p =>
new PersonViewModel()
{
AgeInMonths = p.AgeInMonths,
Title = p.TitleType == null ? null : p.TitleType.Title,
FirstName = p.FirstName,
NickName = p.NickName,
MiddleName = p.MiddleName,
LastName = p.LastName,
Suffix = p.SuffixType == null ? null : p.SuffixType.Suffix,
DateOfBirth = p.DateOfBirth,
DateOfDeath = p.DateOfDeath
}).Count();
The projection just returns the Count here for purposes of this question. What I really want to do is return a list of PersonViewModel's. If a person doesn't have a Title or Suffix, I still want to include that record; I just want that property on the view model to be null. Here it seems like those records are instead simply ignored.
Is this the expected behavior? If so, how can I use null checks in a projection like this without EF ignoring records where the checked properties are null?