3

我完全迷路了。我正在尝试使用 MySQL 设置 MvcMusicStore .Net 应用程序(http://mvcmusicstore.codeplex.com/),但是在编译项目时出现了几个错误;

我已经阅读了http://dev.mysql.com上关于使用 .Net Entity Framework 和 MySQL 的文档,但是我是 EF 的初学者,这些是我没有成功的步骤:

  • 我已经安装了 MySQL Server 5.5

  • 在http://mvcmusicstore.codeplex.com/downloads/get/238258下载了 MvcMusicStore

  • 安装 MySQL Connector Net 6.4.4 并在 mysql 中创建 db: CREATE DATABASE mvcmusicstore/*!40100 CHARACTER SET utf8 COLLATE utf8_general_ci */;

  • 添加了对项目 MvcMusicStore 的以下引用:mysql.data,(未添加 mysql.data.cf 或我收到错误),mysql.data.entity,mysql.web(对于每个库,在属性中,选择“true”复制bin文件夹中的dll)

  • 在“web.config”中替换:

    <connectionStrings>
    <add name="MusicStoreEntities"
    connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf"
    providerName="System.Data.SqlServerCe.4.0"/>
    </connectionStrings>
    

和:

    <connectionStrings>
    <add name="MusicStoreEntities"
    connectionString="Server=127.0.0.1; Database=mvc_store; Uid=root; Pwd={* my password *};"
    providerName="MySQL Data Provider" />
    </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.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
    </system.data>
  • 清理项目->编译并重新编译,然后我收到错误:

“为 system.data 创建配置节处理程序时出错:列 'InvariantName' 被限制为唯一。值 'MySql.Data.MySqlClient' 已经存在。”

所以我已经用如何首先使用 MySql 和实体框架 4.1 代码中找到的代码替换了“dbproviderfactories”部分

    <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.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  • 重新编译,然后我得到错误“找不到数据提供者”:

    Details: 
    ArgumentException: Can not find the data provider. Net Framework required. It may not be installed.
    
    Error in the source code: 
    
    Row 17:         ' the albums with the highest count
    Row 18: 
    Row 19:         Return storeDB.Albums.OrderByDescending(Function(a) a.OrderDetails.Count()).Take(count).ToList()
    Row 20:     End Function
    Row 21: End Class
    
    File: C:\{...}\MvcMusicStore-Completed\MvcMusicStore\Controllers\HomeController.vb    Row: 19 
    
    stack: 
    
    [ArgumentException: Can not find the data provider. Net Framework required. It may not be installed.]
    System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +1420503
    System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name) +393
    System.Data.Entity.Internal.LazyInternalConnection.Initialize() +47
    System.Data.Entity.Internal.LazyInternalConnection.get_ConnectionHasModel() +9
    System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +262
    System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +18
    System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +63
    System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +15
    System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +37
    System.Linq.Queryable.OrderByDescending(IQueryable`1 source, Expression`1 keySelector) +66
    MvcMusicStore.HomeController.GetTopSellingAlbums(Int32 count) in C:\Users\Max\Desktop\Projects\MvcStore\MvcMusicStore-Completed\MvcMusicStore\Controllers\HomeController.vb:19
    MvcMusicStore.HomeController.Index() in C:\Users\Max\Desktop\Projects\MvcStore\MvcMusicStore-Completed\MvcMusicStore\Controllers\HomeController.vb:10
    lambda_method(Closure , ControllerBase , Object[] ) +96
    System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
    System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
    System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
    System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
    System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
    System.Web.Mvc.Controller.ExecuteCore() +116
    System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
    System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
    System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
    System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
    System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
    System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
    System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
    System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8970061
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
    --------------------------------------------------------------------------------
    Microsoft .NET Framework:4.0.30319; ASP.NET:4.0.30319.272 
    

我不知道该怎么做才能解决它。

先感谢您,

最大限度

4

1 回答 1

0

您还记得在您的项目中添加对 MySQL 连接器的引用吗?

于 2012-10-19T17:36:32.757 回答