title: How does EF Core instantiate and initialize entities?
body: <p>How does EF Core instantiate and initialize objects that are retrieved from a database? In the following example, the <code>Person</code> class has a default constructor and a parameterized constructor. <strong>Neither of these constructors is called when my program retrieves the <code>Person</code> object from the database.</strong></p>
  <pre class="lang-cs prettyprint-override"><code>public class Person
  {
      public int Id { get; set; }
      public string FirstName { get; set; }
      public string LastName { get; set; }
      
      public Person()
      {
          Console.WriteLine(&quot;Default ctor accessed&quot;);
      }
      
      public Person(string firstName, string lastName)
      {
          Console.WriteLine(&quot;Parameterized ctor accessed&quot;);
          FirstName = firstName;
          LastName = lastName;
      }
  }
  
  // Program.cs
  // Other code omitted for brevity
  var personRead = context.Persons.First(p =&gt; p.FirstName.Equals(&quot;MyName&quot;));
  Console.WriteLine($&quot;Firstname: {personRead.FirstName}&quot;);
  </code></pre>
  <p>This conflicts with the <a href="https://docs.microsoft.com/en-us/ef/core/modeling/constructors" rel="nofollow noreferrer">microsoft documentation</a>:</p>
  <blockquote>
  <p>When EF Core creates instances of these types, such as for the results of a query, it will first call the default parameterless constructor and then set each property to the value from the database. However, if EF Core finds a parameterized constructor with parameter names and types that match those of mapped properties, then it will instead call the parameterized constructor with values for those properties and will not set each property explicitly</p>
  </blockquote>
  <p>The article was written on 14/10/2020 so it might be out of date. However my question still remains. How does EF core instantiate and initialize these objects? I'm using Microsoft.EntityFrameworkCore version 6.0.8</p>