title: asp.net mvc entity framework code first create database if not exist
body: <p>I have an issue with entity framework . I am using code first approaching but it is not create the database. It is throw an error with following codes in global.asax:</p>
  
  <pre><code>using (resimupDeneme.Data.DataContext db = new DataContext())
          {
              db.Database.CreateIfNotExists();
          }
  </code></pre>
  
  <p>Here is my picture class : </p>
  
  <pre><code>public class foto
  {
      public int fotoId { get; set; }
  
      [Required(ErrorMessage="fotoğraf yolu zorunludur")]
      [DataType(DataType.ImageUrl)]
      public string uzanti{ get; set; }
  
  }
  </code></pre>
  
  <p>And my context class :</p>
  
  <pre><code>public class DataContext : DbContext
  {
  
  
      public DataContext() //i find this codes from internet for a solution for my problem but it is not worked 
          : base("DataContext")
      {
          Database.SetInitializer&lt;DataContext&gt;(new CreateDatabaseIfNotExists&lt;DataContext&gt;());
      }
  
      public DbSet&lt;foto&gt; fotos { get; set; }
  
  }
  </code></pre>