title: Unable to Retrieve Metadata
body: <p><strong>MVC4 + Entity Framework 4.4 + MySql + POCO/Code First</strong></p>
  
  <p>I'm setting up the above configuration .. here are my classes:</p>
  
  <pre><code>namespace BTD.DataContext
  {
  public class BTDContext : DbContext
  {
  
      public BTDContext()
          : base("name=BTDContext")
      {
  
      }
  
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          base.OnModelCreating(modelBuilder);
  
          //modelBuilder.Conventions.Remove&lt;System.Data.Entity.Infrastructure.IncludeMetadataConvention&gt;();
      }
  
      public DbSet&lt;Product&gt; Products { get; set; }
  
      public DbSet&lt;ProductImage&gt; ProductImages { get; set; }        
  
  
  }
  }
  
  namespace BTD.Data
  {
  [Table("Product")]
  public class Product
  {
      [Key]
      public long ProductId { get; set; }
  
      [DisplayName("Manufacturer")]
      public int? ManufacturerId { get; set; }
  
      [Required]
      [StringLength(150)]
      public string Name { get; set; }
  
      [Required]
      [DataType(DataType.MultilineText)]
      public string Description { get; set; }
  
      [Required]
      [StringLength(120)]
      public string URL { get; set; }
  
      [Required]
      [StringLength(75)]
      [DisplayName("Meta Title")]
      public string MetaTitle { get; set; }
  
      [DataType(DataType.MultilineText)]
      [DisplayName("Meta Description")]
      public string MetaDescription { get; set; }
  
      [Required]
      [StringLength(25)]
      public string Status { get; set; }
  
      [DisplayName("Create Date/Time")]
      public DateTime CreateDateTime { get; set; }
  
      [DisplayName("Edit Date/Time")]
      public DateTime EditDateTime { get; set; }
  }
  
  [Table("ProductImage")]
  public class ProductImage
  {
      [Key]
      public long ProductImageId { get; set; }
  
      public long ProductId { get; set; }
  
      public long? ProductVariantId { get; set; }
  
      [Required]
      public byte[] Image { get; set; }
  
      public bool PrimaryImage { get; set; }
  
      public DateTime CreateDateTime { get; set; }
  
      public DateTime EditDateTime { get; set; }
  
  }
  }
  </code></pre>
  
  <p><strong>Here is my web.config setup...</strong></p>
  
  <pre><code>&lt;connectionStrings&gt;
  &lt;add name="BTDContext" connectionString="Server=localhost;Port=3306;Database=btd;User Id=root;Password=mypassword;" providerName="MySql.Data.MySqlClient" /&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <ol>
  <li>The database AND tables already exist...</li>
  <li>I'm still pretty new with mvc but was using <a href="http://dotnetspeak.com/index.php/2010/10/developing-asp-net-mvc-3-application-with-ef-ctp-part-1/" rel="nofollow noreferrer">this tutorial</a></li>
  </ol>
  
  <p>The application builds fine... however when I try to add a controller using Product (BTD.Data) as my model class and BTDContext (BTD.DataContext) as my data context class I receive the following error:</p>
  
  <blockquote>
    <p>Unable to retrieve metadata for BTD.Data.Product using the same
    DbCompiledModel to create context against different types of database
    servers is not supported. Instead, create a separate DbCompiledModel
    for each type of server being used.</p>
  </blockquote>
  
  <p>I am at a complete loss - I've scoured google with almost every different variation of that error message above I can think of but to no avail. </p>
  
  <p><strong>Here are the things i can verify...</strong></p>
  
  <ol>
  <li>MySql is working properly</li>
  <li>I'm using MySql Connector version 6.5.4 and have created other ASP.net web forms + entity framework applications with ZERO problems</li>
  </ol>
  
  <p><strong>I have also tried including/removing this in my web.config:</strong></p>
  
  <pre><code>&lt;system.data&gt;
  &lt;DbProviderFactories&gt;
    &lt;remove invariant="MySql.Data.MySqlClient"/&gt;
    &lt;add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /&gt;
  &lt;/DbProviderFactories&gt;
  </code></pre>
  
  <p></p>
  
  <p>I've literally been working on this bug for days - I'm to the point now that I would be willing to pay someone to solve it.. no joke... I'd really love to use MVC 4 and Razor - I was so excited to get started on this, but now i'm pretty discouraged - I truly appreciate any help/guidance on this!</p>
  
  <p>Also note - i'm using Entityframework from Nuget...</p>
  
  <p><strong>Another Note</strong></p>
  
  <p>I was using the default visual studio template that creates your MVC project with the account pages and other stuff. I JUST removed all references to the added files because they were trying to use the "DefaultConnection" which didn't exist - so i thought those files may be what was causing the error - however still no luck after removing them - </p>
  
  <p>I just wanted to let everyone know i'm using the visual studio MVC project template which pre-creates a bunch of files. I will be trying to recreate this all from a blank MVC project which doesn't have those files - i will update this once i test that</p>
  
  <p><strong>UPDATE TO USING VS MVC Basic Template:</strong> Same error resulted - still no solution</p>
  
  <p><strong>ANOTHER PERSON EXPERIENCING THE SAME PROBLEM</strong></p>
  
  <p><a href="https://stackoverflow.com/questions/12165185/mvc4-scaffolding-add-controller-gives-error-unable-to-retrieve-metadata?rq=1">Right here is another stackoverflow question that mimics mine</a> - however I tried his solution to no avail - maybe someone else who is having this same problem can benefit from the link</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I recently just tried putting this into MS Sql Server and the view scaffolding adds fine with no error - so I'm not sure if its my MySql database or connection string or what... driving me nuts..</p>
  
  <p><strong>Other References</strong></p>
  
  <p>It appears someone else is having the same issues I am - the only difference is they are using sql server - I tried tweaking all my code to follow the suggestions on <a href="https://stackoverflow.com/questions/12172074/add-controller-in-mvc4-not-working">this stackoverflow question/answer here</a> but still to no avail</p>
  
  <p><strong>POSSIBLE FIX???</strong></p>
  
  <p>So this is weird... after hooking it up to MS Sql Server and adding the controller, then reverting the connection string to MySql it is actually WORKING with MySql... what the heck!?? </p>
  
  <p>So it seems that when you try to add your controller and the view scaffolding (is that the right phrase?) is added WITH the mysql connection string it fails...however if you hook it up to a sql server db, generate the scaffolding/controller, then revert to mysql connection string it works.... ?!?!</p>