title: Why does adding a parameterless constructor to my entity model class work here? What are the implications?
body: <p>So I have this office entity class:</p>
  
  <pre><code>[Table("office_entity")]
  public class EFOffice : EFBusinessEntity
  {
  
      [Column("address")]
      [StringLength(250)]
      public string Address { get; set; }
  
      [Column("business_name")]
      [StringLength(150)]
      public string BusinessName { get; set; }
  
      public virtual ICollection&lt;EFEmployee&gt; Employees { get; set; }
  
      public EFOffice(Guid id, Guid tenantId, string address, string businessName)
      {
          this.Id = id;
          this.TenantId = tenantId;
          this.Address = address;
          this.BusinessName = businessName;
      }
  }
  </code></pre>
  
  <p>I'm implementing a generic repository, and I just added this method that checks if an entity already exists in the repository:</p>
  
  <pre><code>public bool Exists&lt;TEntity&gt;(Guid key) where TEntity : class, IBusinessEntity
  {
      return (_context.Set&lt;TEntity&gt;().Find(key) != null);
  }
  </code></pre>
  
  <p>Then I wrote the following test code:</p>
  
  <pre><code>public void TestExists1()
  {
      InitializeDatabase();
      EFOffice testOffice = InitializeOffice1();
      Debug.Assert(EFRepo.Exists&lt;EFOffice&gt;(testOffice.Id));
  }
  </code></pre>
  
  <p>The method for InitializeOffice1() is as follows:</p>
  
  <pre><code>private EFOffice InitializeOffice1()
  {
      EFOffice newOffice = new EFOffice(SparkTest.TestGuid1, SparkTest.TestGuid2, "Generic Address", "HQ");
      return newOffice;
  }
  </code></pre>
  
  <p>The test is supposed to pass because I already inserted the office returned by InitializeOffice1() previously. However, I get the following error:</p>
  
  <blockquote>
    <p>System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: The class 'Models.Employees.EF.EFOffice' has no parameterless constructor.</p>
  </blockquote>
  
  <p>So then I added this to the EFOffice class shown at the top:</p>
  
  <pre><code>private EFOffice()
  {
  
  }
  </code></pre>
  
  <p>And for some reason the test now passes. Can anyone explain what's going on? And does having a parameterless constructor have bad side effects? It's important that every office I insert has an id, a tenantId, an address and a businessName, as listed in the constructor at the top.</p>