无法检索元数据 [英] Unable to Retrieve Metadata

查看:169
本文介绍了无法检索元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MVC4 +实体框架4.4 + MYSQL + POCO / code首先

我设置了​​上面的配置..这里是我的类:

 命名空间BTD.DataContext
{
公共类BTDContext:的DbContext
{    公共BTDContext()
        :基地(NAME = BTDContext)
    {    }    保护覆盖无效OnModelCreating(DbModelBuilder模型构建器)
    {
        base.OnModelCreating(模型构建器);        //modelBuilder.Conventions.Remove<System.Data.Entity.Infrastructure.IncludeMetadataConvention>();
    }    公共DbSet&LT;产品与GT;产品{搞定;组; }    公共DbSet&LT; ProductImage&GT; ProductImages {搞定;组; }
}
}命名空间BTD.Data
{
[表(产品)]
公共类产品
{
    [键]
    众长{产品编号搞定;组; }    [DisplayName的(制造商)]
    公众诠释? ManufacturerId {搞定;组; }    [需要]
    [StringLength(150)]
    公共字符串名称{;组; }    [需要]
    [数据类型(DataType.MultilineText)
    公共字符串描述{搞定;组; }    [需要]
    [StringLength(120)]
    公共字符串URL {搞定;组; }    [需要]
    [StringLength(75)]
    [显示名称(元标题)
    公共字符串MetaTitle {搞定;组; }    [数据类型(DataType.MultilineText)
    [显示名称(元说明)]
    公共字符串MetaDescription {搞定;组; }    [需要]
    [StringLength(25)]
    公共字符串状态{搞定;组; }    [显示名称(创建日期/时间)]
    公众的DateTime CreateDateTime {搞定;组; }    [DisplayName的(编辑日期/时间)]
    公众的DateTime EditDateTime {搞定;组; }
}[表(ProductImage)]
公共类ProductImage
{
    [键]
    众长ProductImageId {搞定;组; }    众长{产品编号搞定;组; }    众长? ProductVariantId {搞定;组; }    [需要]
    公众的byte []图片{搞定;组; }    公共BOOL PrimaryImage {搞定;组; }    公众的DateTime CreateDateTime {搞定;组; }    公众的DateTime EditDateTime {搞定;组; }}
}

这里是我的web.config设置...

 &LT;&是connectionStrings GT;
&LT;添加名称=BTDContext的connectionString =服务器=本地主机,端口= 3306;数据库= BTD;用户ID =根;密码= myPassword;复制代码的providerName =MySql.Data.MySqlClient/&GT;
&LT; /&是connectionStrings GT;


  1. 数据库和表已经存在...

  2. 我还在pretty新与MVC,但使用<一个href=\"http://dotnetspeak.com/index.php/2010/10/developing-asp-net-mvc-3-application-with-ef-ctp-part-1/\">this教程

应用程序构建罚款...但是当我尝试添加使用控制器产品(BTD.Data)作为我的模型类和BTDContext(BTD.DataContext)作为我的数据上下文类我收到以下错误:


  

无法使用同样的检索元数据BTD.Data.Product
  DbCompiledModel打造针对不同类型的数据库的情况下
  不支持的服务器。相反,创建一个单独的DbCompiledModel
  对于每个类型的服务器被使用。


我完全茫然 - 我已经冲刷谷歌与错误信息上面我能想到的,但无济于事的几乎每一个不同变化。

这里的事情,我可以验证...


  1. MySQL是正常工作

  2. 我使用的MySQL Connector 6.5.4版,并创造了其他ASP.net web表单+实体框架的应用程序与零问题

我自己也尝试包括/在我的web.config删除此:

 &LT;&System.Data这GT;
&LT; D​​bProviderFactories&GT;
  &LT;清除不变=MySql.Data.MySqlClient/&GT;
  &LT;添加名称=MySQL的数据提供程序不变=MySql.Data.MySqlClient描述= TYPE =MySql.Data.MySqlClient.MySqlClientFactory,MySql.Data,版本= 6.5.4.0MySQL的净Framework数据提供程序。文化=中性公钥= c5687fc88969c44d/&GT;
&LT; / DbProviderFactories&GT;

我字面上一直在这个bug天 - 我的一点现在我愿意花钱找人来解决它..没有开玩笑......我真的很喜欢使用MVC 4剃须刀 - 我很高兴能在这个起家,但现在我pretty气馁! - 我真正的AP preciate任何帮助/指导

另外请注意 - 我使用的EntityFramework从...的NuGet

另注

我是使用与该帐户页面和其他的东西你创建MVC项目的默认Visual Studio的模板。我只是删除到添加的文件的所有引用,因为他们试图用DefaultConnection,这是不存在的 - 所以我想这些文件可能是什么造成的错误 - 但仍然取出之后,没有运气 -

我只想让大家知道我在使用Visual Studio MVC项目模板,pre-创建一堆文件。我将努力重建所有这一切从没有这些文件的空白MVC项目 - 我会更新一次这个我测试

更新使用MVC VS基本的模板:同样的错误导致 - 仍然无解

其他个人遇到同样的问题

<一个href=\"http://stackoverflow.com/questions/12165185/mvc4-scaffolding-add-controller-gives-error-unable-to-retrieve-metadata?rq=1\">Right这里要说的是模仿雷的另一个计算器的问题 - 但是我想他的解决办法都无济于事 - 也许别人谁是有同样的问题可以通过链接

受益

更新

我刚刚试图把这个到MS SQL Server和视图脚手架增加了罚款,并没有错误 - 所以我不知道如果我的MySQL数据库或连接字符串或者是什​​么......我发疯..

其他参考

这似乎是别人有我同样的问题 - 唯一的区别是他们使用的是SQL Server的 - 我想调整我的所有code到遵循的这个计算器问题/答案这里,但仍然无济于事。

可能的修复???

因此​​,这是奇怪的...它挂钩到M​​S SQL Server和添加控制器,然后恢复连接字符串到MySql它实际上是使用MySQL后......到底是什么!?

如此看来,当您尝试添加控制器和视图脚手架(是正确的短语?)是它失败的MySQL连接字符串添加......但是如果你把它挂到一个SQL Server数据库,生成脚手架/控制器,然后恢复到MySQL的连接字符串工程....?!?!


解决方案

似乎MVC4控制器脚手架没有正确认识MySQL连接字符串。更改连接字符串如下图所示产生EF CRUD code的控制器时:

 &LT;&是connectionStrings GT;
    &LT;添加名称=BTDContext的connectionString =数据源= HOST_NAME;数据库=数据库名称; UID = USER_ID; PWD =密码;的providerName =System.Data.SqlClient的/&GT;
&LT; /&是connectionStrings GT;

在运行应用程序时,将其改回标准:

 &LT;&是connectionStrings GT;
    &LT;添加名称=BTDContext的connectionString =数据源= HOST_NAME;数据库=数据库名称; UID = USER_ID; PWD =密码;的providerName =MySql.Data.MySqlClient/&GT;
&LT; /&是connectionStrings GT;

请注意的变化,供应商的名称。

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>

  1. The database AND tables already exist...
  2. 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...

  1. MySql is working properly
  2. 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

UPDATE TO USING VS MVC Basic Template: Same error resulted - still no solution

ANOTHER PERSON EXPERIENCING THE SAME PROBLEM

Right here is another stackoverflow question that mimics mine - however I tried his solution to no avail - maybe someone else who is having this same problem can benefit from the link

UPDATE

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..

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

POSSIBLE FIX???

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!??

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.... ?!?!

解决方案

It seems that MVC4 Controller scaffolding is not properly recognizing MySql Connection String. Change the connection string as shown below when generating EF CRUD code for Controllers:

<connectionStrings>
    <add name="BTDContext" connectionString="Data Source=host_name;Database=database_name;uid=user_id;pwd=password;" providerName="System.Data.SqlClient" /> 
</connectionStrings>

Change it back to standard when running the application:

<connectionStrings>
    <add name="BTDContext" connectionString="Data Source=host_name;Database=database_name;uid=user_id;pwd=password;" providerName="MySql.Data.MySqlClient" /> 
</connectionStrings>

Note the change, provider name.

这篇关于无法检索元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆