title: ASP.NET Core MVC & C# : insert data into database using Entity Framework
body: <p>I am trying to insert data from my ASP.NET Core MVC application with Entity Framework to my SQL Server database on localhost.</p>
  
  <p>My model class looks like this:</p>
  
  <pre><code>public class Auto
  {
      public string Motorleistung { get; set; }
      public string Lackierung { get; set; }
      public string Felgen { get; set; }
      public string Sonderleistungen { get; set; }
  }
  </code></pre>
  
  <p>I already added the <code>DbContext</code> in a new folder (<code>Services/AutoContext</code> class):</p>
  
  <pre><code>public class AutoContext : DbContext
  {
      DbSet&lt;Auto&gt; Autos { get; set; }
  
      public AutoContext(DbContextOptions&lt;AutoContext&gt; options)
          : base(options)
      {
          Database.EnsureCreated();
      }
  }
  </code></pre>
  
  <p>I added this part to the <code>Startup.cs</code> file in the <code>ConfigurateServices</code> method:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
          var connectionString = "Server=localhost;Database=Auto;User Id=sa;Password=YourPassword123";
  
          services.AddControllersWithViews();
          services.AddDbContext&lt;AutoContext&gt;(o =&gt; o.UseSqlServer(connectionString));
  }
  </code></pre>
  
  <p>I am trying to use a class extension with a method to insert properties from auto into the DB:</p>
  
  <pre><code>public static class AutoContextExtensions
  {
      public static void CreateSeedData(this AutoContext context)
      {
          var auto = new List&lt;Auto&gt;()
              {
                  new Auto()
                  {
                      Motorleistung = "500 PS",
                      Lackierung = "Gelb",
                      Felgen = "Chrome",
                      Sonderleistungen = "Sitzheizung"
                  }
              };
          context.AddRange(auto);
          context.SaveChanges();
      }
  }
  </code></pre>
  
  <p>I am now trying to call the <code>CreateSeedData</code> function from the <code>Startup.cs</code> to pass the data into my database like:</p>
  
  <pre><code>Projectname.AutoContextExtensions.CreateSeedData();
  </code></pre>
  
  <p>It expects me to give a parameter. What parameter do I have to pass? 
  (I extracted the code from a sample) </p>