0

我 git clone Nuget Gallery,它基于 sql server。

由于 NuGet 库使用实体框架 6,我尝试按照以下步骤迁移到 mysql:

1.将web.config的connectionStrings替换为以下

<add name="Gallery.SqlServer" connectionString="server=localhost;uid=root;password=123456;database=NuGetGallery" providerName="MySql.Data.MySqlClient"/>
<add name="Gallery.SupportRequestSqlServer" connectionString="server=localhost;userid=root;password=123456;database=SupportRequest" providerName="MySql.Data.MySqlClient"/>

2.将 entityframework 部分替换为以下内容:

<entityFramework codeConfigurationType="NuGetGallery.EntitiesConfiguration, NuGetGallery.Core">
<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>

3.[DbConfigurationType(typeof(EntitiesConfiguration))]替换[DbConfigurationType(typeof(MySqlEFConfiguration))] EntitiesContext和SupportRequestDbContext

4.将 EntitiesConfiguration() 构造函数替换为

    public EntitiesConfiguration()
    {
        // Configure Connection Resiliency / Retry Logic
        // See https://msdn.microsoft.com/en-us/data/dn456835.aspx and msdn.microsoft.com/en-us/data/dn307226
        SetExecutionStrategy(MySqlProviderInvariantName.ProviderName, () => new MySqlExecutionStrategy());
    }

但是,运气不好!

当我执行Update-Database -ConfigurationTypeName MigrationsConfiguration -Verbose时,它引发了如下异常:

使用启动项目“NuGetGallery”。使用 NuGet 项目“NuGetGallery”。指定“-Verbose”标志以查看应用于目标数据库的 SQL 语句。System.NullReferenceException: 未将对象引用设置到对象的实例中。 在 MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(DbConnection connection) 在 System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) System.Data .Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection 连接) 在 System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.<>c__DisplayClass1.b__0(Tuple 3 k) 在 System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) 在 System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.ResolveManifestToken(DbConnection connection) 在 System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest) 在 System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) 在 System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) 在 System.Data.Entity.Internal.RetryLazy2.GetValue(TInput 输入) 在 System.Data.Entity.Internal.LazyInternalContext.InitializeContext() 在 System.Data.Entity.Internal.InternalContext.ForceOSpaceLoadingForKnownEntityTypes() 在 System.Data.Entity.DbContext.System.Data.Entity。 Infrastructure.IObjectContextAdapter.get_ObjectContext() 在 NuGetGallery.ObjectMaterializedInterceptingDbContext.get_ObjectContext() 位置 E:\git\HSY.NugetGallery\src\NuGetGallery.Core\Entities\Interception\ObjectMaterializedInterceptingDbContext.cs: 行号 35 在 NuGetGallery.ObjectMaterializedInterceptingDbContext..ctor( String connectionString) 位置 E:\git\HSY.NugetGallery\src\NuGetGallery.Core\Entities\Interception\ObjectMaterializedInterceptingDbContext.cs:行号 19 在 NuGetGallery.EntitiesContext..ctor(String connectionString, Boolean readOnly) 位置 E:\git\ HSY。NugetGallery\src\NuGetGallery.Core\Entities\EntitiesContext.cs:行号 42 在 NuGetGallery.EntitiesContext..ctor() 位置 E:\git\HSY.NugetGallery\src\NuGetGallery.Core\Entities\EntitiesContext.cs:行号34

4

0 回答 0