How to use MySql and Entity Framework 4.1 code first

佐手、 提交于 2019-12-03 11:04:20

问题


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

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)


回答1:


Try this code:

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


来源:https://stackoverflow.com/questions/5764765/how-to-use-mysql-and-entity-framework-4-1-code-first

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!