Driving me INSANE: Unable to Retrieve Metadata for
Posted
by
Loren
on Stack Overflow
See other posts from Stack Overflow
or by Loren
Published on 2012-09-22T18:27:44Z
Indexed on
2012/09/22
21:37 UTC
Read the original article
Hit count: 626
I've been spending the past 3 days trying to fix this problem I'm encountering - it's driving me insane... I'm not quite sure what is causing this bug - here are the details:
MVC4 + Entity Framework 4.4 + MySql + POCO/Code First
I'm setting up the above configuration .. here are my classes:
namespace BTD.DataContext
{
public class BTDContext : DbContext
{
public BTDContext()
: base("name=BTDContext")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
//modelBuilder.Conventions.Remove<System.Data.Entity.Infrastructure.IncludeMetadataConvention>();
}
public DbSet<Product> Products { get; set; }
public DbSet<ProductImage> 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; }
}
}
Here is my web.config setup...
<connectionStrings>
<add name="BTDContext" connectionString="Server=localhost;Port=3306;Database=btd;User Id=root;Password=mypassword;" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
- The database AND tables already exist...
- I'm still pretty new with mvc but was using this tutorial
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:
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.
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.
Here are the things i can verify...
- MySql is working properly
- I'm using MySql Connector version 6.5.4 and have created other ASP.net web forms + entity framework applications with ZERO problems
I have also tried including/removing this in my web.config:
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient"/>
<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" />
</DbProviderFactories>
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!
Also note - i'm using Entityframework from Nuget...
Another Note
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 -
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
Other References
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 this stackoverflow question/answer here but still to no avail
© Stack Overflow or respective owner