1. <legend id='xSqTj'><style id='xSqTj'><dir id='xSqTj'><q id='xSqTj'></q></dir></style></legend>
    <tfoot id='xSqTj'></tfoot>
      • <bdo id='xSqTj'></bdo><ul id='xSqTj'></ul>

      <i id='xSqTj'><tr id='xSqTj'><dt id='xSqTj'><q id='xSqTj'><span id='xSqTj'><b id='xSqTj'><form id='xSqTj'><ins id='xSqTj'></ins><ul id='xSqTj'></ul><sub id='xSqTj'></sub></form><legend id='xSqTj'></legend><bdo id='xSqTj'><pre id='xSqTj'><center id='xSqTj'></center></pre></bdo></b><th id='xSqTj'></th></span></q></dt></tr></i><div id='xSqTj'><tfoot id='xSqTj'></tfoot><dl id='xSqTj'><fieldset id='xSqTj'></fieldset></dl></div>

    1. <small id='xSqTj'></small><noframes id='xSqTj'>

      在实体框架 4 和代码优先开发 CTP 中使用 MySql

      时间:2023-06-02
    2. <tfoot id='N33K2'></tfoot>

      1. <i id='N33K2'><tr id='N33K2'><dt id='N33K2'><q id='N33K2'><span id='N33K2'><b id='N33K2'><form id='N33K2'><ins id='N33K2'></ins><ul id='N33K2'></ul><sub id='N33K2'></sub></form><legend id='N33K2'></legend><bdo id='N33K2'><pre id='N33K2'><center id='N33K2'></center></pre></bdo></b><th id='N33K2'></th></span></q></dt></tr></i><div id='N33K2'><tfoot id='N33K2'></tfoot><dl id='N33K2'><fieldset id='N33K2'></fieldset></dl></div>

              <tbody id='N33K2'></tbody>
            <legend id='N33K2'><style id='N33K2'><dir id='N33K2'><q id='N33K2'></q></dir></style></legend>
              • <bdo id='N33K2'></bdo><ul id='N33K2'></ul>

                <small id='N33K2'></small><noframes id='N33K2'>

              • 本文介绍了在实体框架 4 和代码优先开发 CTP 中使用 MySql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想我会尝试一下 Scott Guthrie 的 最新文章 使用实体框架 4 进行代码优先开发.我尝试使用 MySql,而不是使用 Sql Server.这是我的 web.config 的相关部分(这是一个 Asp.Net MVC 2 应用程序):

                I thought I'd experiment a bit with Scott Guthrie's latest post on code-first dev with Entity Framework 4. Instead of using Sql Server, I'm trying to use MySql. Here are the relevant parts of my web.config (this is an Asp.Net MVC 2 app):

                <connectionStrings>
                    <add name="NerdDinners"
                         connectionString="Server=localhost; Database=NerdDinners; 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.2.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
                    </DbProviderFactories>
                  </system.data>
                

                就像教程一样,我希望 EF4 自动为我生成数据库.相反,它抛出一个 ProviderIncompatibleException,内部异常抱怨 NerdDinners 数据库不存在.

                Just like the tutorial, I'm expecting EF4 to generate the db for me automatically. Instead, it throws a ProviderIncompatibleException, with an inner exception complaining that the NerdDinners database doesn't exist.

                很公平;我去为它创建了 MySql 数据库只是为了看看事情是否可行,并得到了另一个 ProviderIncompatibleException .这次,提供程序不支持DatabaseExists".

                Fair enough; I went and created the MySql db for it just to see if things would work, and got another ProviderIncompatibleException instead. This time, "DatabaseExists is not supported by the provider".

                我承认,这是我第一次真正深入研究实体框架(我主要坚持使用 Linq to Sql),而且这一切都在上周发布的 Code-First CTP 上运行.也就是说,我在这里做错了什么,或者是可以解决的已知问题吗?

                I'll admit, this is the first time I'm really delving into Entity Framework (I've stuck mostly to Linq to Sql), and this is all running on the Code-First CTP released only last week. That said, is there something I'm doing wrong here, or a known problem that can be worked around?

                推荐答案

                好的,终于有了几个兴趣点.

                Right, finally got it working with a few points of interest.

                • 无法创建数据库,必须已经存在
                • 您必须使用 DBContext 名称为每个数据库竞赛创建一个连接字符串(在上面的示例中,连接字符串必须存在名称为NerdDinners"),而不仅仅是默认的(否则它将使用 SQL)
                • 它将使用您用来定义上下文的 DBSet 名称作为表的名称,因此命名它们时要小心.

                总之,路漫漫其修远兮

                **更新另一点要注意,当使用 MySQL 部署您的 MVC 站点时,您最喜欢还需要将 DataFactory 添加到您的 web.config.通常是因为 MySql 连接器和支持的 MySQL 版本不同.(经过多次摸索后通过其他来源找到的答案)只需添加:

                **Update Another point to note, when deploying your MVC site using MySQL you will most like need also add a DataFactory to your web.config. Usually because of the difference in MySql connectors out there and the versions of MySQL that are supported. (answer found through other sources after much head scratching) Just add:

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

                作为 web.config 的一个单独部分 确保设置与站点一起部署的 MySQL.Data.dll 的版本号(复制为本地"也是一个好主意)MySQL DLL 以确保兼容性.

                As a seperate section to your web.config making sure to set the version number of the MySQL.Data.dll you deploy with the site (also a good idea to "copy as local" your MySQL DLLs to ensure compatibility.

                这篇关于在实体框架 4 和代码优先开发 CTP 中使用 MySql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何使用 group-concat mysql 创建 json 格式? 下一篇:计算表格行数

                相关文章

              • <tfoot id='6BRPd'></tfoot>

                  <i id='6BRPd'><tr id='6BRPd'><dt id='6BRPd'><q id='6BRPd'><span id='6BRPd'><b id='6BRPd'><form id='6BRPd'><ins id='6BRPd'></ins><ul id='6BRPd'></ul><sub id='6BRPd'></sub></form><legend id='6BRPd'></legend><bdo id='6BRPd'><pre id='6BRPd'><center id='6BRPd'></center></pre></bdo></b><th id='6BRPd'></th></span></q></dt></tr></i><div id='6BRPd'><tfoot id='6BRPd'></tfoot><dl id='6BRPd'><fieldset id='6BRPd'></fieldset></dl></div>

                    <legend id='6BRPd'><style id='6BRPd'><dir id='6BRPd'><q id='6BRPd'></q></dir></style></legend>

                    • <bdo id='6BRPd'></bdo><ul id='6BRPd'></ul>
                  1. <small id='6BRPd'></small><noframes id='6BRPd'>