Entity Framework - Lazyload with null-enabled property

Asked

Viewed 23 times

2

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

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

That object ocorrencia may own the property Pessoa as null.

To 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; }
    }

The Occurrence object will be returned with the Null Person object, or nothing will be returned?

1 answer

2


The Occurrence object will be returned with the Null Person object, or nothing will be returned?

By its mapping, nothing will be returned, as the anticipated charge resolution will be by INNER JOIN because of that:

public int PessoaId { get; set; }

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

public int? PessoaId { get; set; }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.