首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >实体框架6和MySQL,模型优先

问实体框架6和MySQL,模型优先
EN

Stack Overflow用户
提问于 2014-01-02 14:23:45
回答 1查看 16.2K关注 0票数 2

我在使用实体框架6和MySQL以及在ASP.NET C# MVC 3中使用技术时遇到了问题。

目前的情况是,我得到了一个错误:

代码语言:javascript
复制
Keyword not supported.
Parameter name: metadata

元数据在web.config -file中的连接字符串中指定:

代码语言:javascript
复制
<add name="SiteNameContainer" 
  connectionString="metadata=res://*/Models. SiteName.csdl|
    res://*/Models. SiteName.ssdl|
    res://*/Models. SiteName.msl;
    provider=MySql.Data.MySqlClient;
    provider connection string='server=127.0.0.1;
    user id=fire;password=fire_db;
    database=fire_dotnet'" 
  providerName="MySql.Data.MySqlClient" />

我试图删除connectionString中的元数据部分,但是它说关键字“provider”不受支持,然后不支持“provider connection string”。

我的web.config文件中还有以下两个部分:

代码语言:javascript
复制
<entityFramework>
    <providers>
        <provider invariantName="MySql.Data.MySqlClient" 
            type="MySql.Data.MySqlClient.MySqlProviderServices, 
            MySql.Data.Entity.EF6, Version=6.8.3.0, 
            Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </providers>
</entityFramework>
<system.data>
<DbProviderFactories>
    <clear />
    <remove invariant="MySql.Data.MySqlClient" />
    <add name="MySql.Data.MySqlClient" 
        invariant="MySql.Data.MySqlClient" 
        description=".Net Framework Data Provider for MySQL" 
        type="MySql.Data.MySqlClient.MySqlClientFactory, 
        MySql.Data, Version=6.8.3.0, Culture=neutral, 
        PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>

我引用了MySQL网络连接器6.8.3文件(MySql.Data,MySql.Data.Entity.EF6,MySql.Web).

我的要求是我必须使用 MySQL 和Entity Framework6,而.NET连接器的changelog表示6.8.x增加了对MySQL的支持。

我没有主意了,希望有人能帮我这个忙。提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2014-02-09 11:31:28

似乎您在连接字符串中使用了错误的providerName,应该是System.Data.EntityClient。

下面是我最后如何让我的模型第一次使用MySQL的代码,以及我的app.config是什么样子的:

代码语言:javascript
复制
<connectionStrings>
  <add name="MyEntities"
       connectionString="metadata=res://*/Data.Entity.Model.csdl|res://*/Data.Entity.Model.ssdl|res://*/Data.Entity.Model.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;Data Source=localhost;User Id=dbadmin;Password=password;Initial Catalog=database_name;&quot;"
       providerName="System.Data.EntityClient"/>
</connectionStrings>

如果这不起作用,下面是entityFramework部分。您将注意到我在下一节中使用的codeConfigurationType属性。它为MySQL添加了依赖解析器,但是还有其他方法可以在MySQL: EF 6 Support文档中看到。

代码语言:javascript
复制
<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
  <providers>
    <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"/>
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
  </providers>
</entityFramework>
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20885034

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档