Entity Framework - LazyLoad with property that allows null

2

What happens to a search that uses include of Entity Framework in a property that can be null.

var ocorrencia = db.Ocorrencia
            .Include("Pessoa")
            .FirstOrDefault(c => c.id == 3);

This ocorrencia object can have the Pessoa property as null .

A model :

public partial class Ocorrencia
{
    [Key]
    public int id { get; set; }
    public Pessoa Pessoa { get; set; }
    public int PessoaId { get; set; }
}

public class Pessoa
    {
        [Key]
        public int id { get; set; }
        public string nome { get; set; }
    }

Will the Occurrence object be returned with the Person null object, or will nothing be returned?

    
asked by anonymous 22.03.2017 / 22:50

1 answer

2
  

Will the object Occurrence be returned with the null person object, or will nothing be returned?

Because of its mapping, nothing will be returned, as the preload resolution will be by INNER JOIN because of this:

public int PessoaId { get; set; }

To resolve to LEFT OUTER JOIN , it would have to be:

public int? PessoaId { get; set; }
    
22.03.2017 / 23:04