title: Entity Framework Core model with abstract class
body: <p>I have a question</p>
  
  <p>I make a Code First Database In <code>ASP .NET Core 2.1</code> and <code>Entity Framework 2.1.1</code>. For now, im in a planning step and i have one question. I want to have a list of instance of abstract worker's class with method, that will work difrently. My code:</p>
  
  <p>I have a <code>Farm</code>:</p>
  
  <pre><code>public class Farm
      {
          [Key]
          public int Id { get; set; }
          public string Name { get; set; }
  
          public virtual List&lt;Farmer&gt; Farmers { get; set; } //my problem
          public virtual List&lt;Driver&gt; Drivers { get; set; } //starts here!
      }
  </code></pre>
  
  <p>In Farm instance i have Workers. I made an <code>abstract class</code> for it:</p>
  
  <pre><code>public abstract class Worker
  {
      [Key]
      public int Id { get; set; }
  
      [ForeignKey("Farm")]
      public int FarmId { get; set; }
      public Farm Farm { get; set; }
  
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public float UsdPerHour { get; set; }
      public int HoursPerDay { get; set; }
      public int DaysOfWork { get; set; }
  
      public abstract float CountSalary();
  }
  </code></pre>
  
  <p>Worker can be a <code>Driver</code> or a <code>Farmer</code>:</p>
  
  <pre><code>public class Farmer : Worker
  {
      public float UsdPerHour = 9;
      public int HoursPerDay = 8;
      public int DaysOfWork = 20; 
      // CountSalary() here, but in diffrent way!
  }
  
  public class Driver : Worker
  {
      public float UsdPerHour = 10;
      public int HoursPerDay = 7;
      public int DaysOfWork = 18;
      // CountSalary() here, but in diffrent way!
  }
  </code></pre>
  
  <p>And my <code>FarmDbContext</code>:</p>
  
  <pre><code>public class FarmDbContext : DbContext
  {
      public FarmDbContext(DbContextOptions&lt;FarmDbContext&gt; options) : base(options) { }
  
      public DbSet&lt;Farm&gt; Farms { get; set; }
      //public DbSet&lt;Worker&gt; Workers { get; set; }
      public DbSet&lt;Farmer&gt; Farmers { get; set; } // What to do here?
      public DbSet&lt;Driver&gt; Drivers { get; set; } // Let Farmers and Drivers
                                                 // Or Workers?
  }
  </code></pre>
  
  <p>In My <code>farm</code> i have two kinds of workers. For each "Position" i want to count salary in diffrent way. </p>
  
  <p>What i want to do in code:</p>
  
  <pre><code>var Workers = List&lt;Worker&gt;
  Workers.Add(New Driver());
  Workers.Add(new Farmer()): 
  
  foreach(object o in Workers)
     int salary = o.CountSalary()
  
  // i know that code is wrong, but i describe the way that i want to achive my goal
  </code></pre>
  
  <p>Could you explain me, how to plan my <code>DbContext</code> to achive, what i want to? <code>Farmer</code> and <code>Driver</code> need to have hard-coded values of propertys. When i let <code>DbContext</code> like above in my code, i get two tables, <code>dbo.Drivers</code> and <code>dbo.Farmers</code>. If it will work in a way that i explained above? Is it possible in EF to block that hardcoded value in database and have it in every record of data i tables?</p>