I have a Job entity with an optional Contract child entity (using Entity Framework)
public class Job
{
public string Title { get; set; }
public Guid? ContractId { get; set; }
public virtual Contract Contract { get; set; }
}
public class Contract
{
public DateTime StartDate{ get; set; }
}
I have the following DTO
public class JobDto
{
public string Title { get; set; }
public DateTime ContractStartDate { get; set; }
}
I project to the DTO using AutoMapper Queryable extensions.
c.CreateMap<WorkTask, WorkTaskDtoLite>();
var jobDtos = _context.Jobs.ProjectTo<JobDto>().ToList();
Then this generates INNER joins, so does not return any JobDtos where there is no Contract. I need OUTER joins...
I'm really not sure how to fix this. I have referred to https://github.com/AutoMapper/AutoMapper/wiki/Queryable-Extensions but this does not seem to address this basic issue.
Any help appreciated!
UPDATE
Thanks all but seems to be an underlying issue with Entity Framework Core RC1.
See bug report here:
https://github.com/aspnet/EntityFramework/issues/3186
With suggested work-around here:
https://github.com/aspnet/EntityFramework/commit/c4e44471b6f41f96d37b1acfbbb4cc97cd11ee89