如何首先使用MySql和Entity Framework 4.1代码 [英] How to use MySql and Entity Framework 4.1 code first
问题描述
我正在尝试在MVCMusicStore中使用MySQL数据库
http://mvcmusicstore.codeplex.com/而不是MSSQL.
我想学习使用MySQL进行代码优先开发.
我已经将这些代码添加到web.config
I am trying to use MySQL database in MVCMusicStore
http://mvcmusicstore.codeplex.com/ instead of MSSQL.
I would like to learn Code first development with MySQL.
I had added these code to web.config
<connectionStrings>
<add name="MusicStoreEntities"
connectionString="Server=localhost; Database=MvcMusicStore; Uid=root; Pwd=;"
providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
<system.data>
<DbProviderFactories>
<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.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
MySQL数据库已创建,但未创建表.
我刚刚在项目中添加了Mysql.Data.MySQLClient.dll
引用.
而且我有这种例外情况:
MySQL database is already created but tables are not created.
I have just added Mysql.Data.MySQLClient.dll
reference to my project.
And I have this kind of exception:
为system.data创建配置节处理程序时发生错误:
列'InvariantName'被限制为唯一.
值'MySql.Data.MySqlClient'已经存在.
(C:\ Users \ Dauren \ Downloads \ MvcMusicStore-v3.0 \ MvcMusicStore-v3.0 \ MvcMusicStore-Completed \ MvcMusicStore \ web.config第47行)
An error occurred creating the configuration section handler for system.data:
Column 'InvariantName' is constrained to be unique.
Value 'MySql.Data.MySqlClient' is already present.
(C:\Users\Dauren\Downloads\MvcMusicStore-v3.0\MvcMusicStore-v3.0\MvcMusicStore-Completed\MvcMusicStore\web.config line 47)
推荐答案
尝试以下代码:
<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.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
这篇关于如何首先使用MySql和Entity Framework 4.1代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!