如何使Nuget Gallery支持mysql?

时间:2019-04-26 02:44:29

标签: c# mysql entity-framework-6 nugetgallery

我git克隆了Nuget Gallery,它基于sql服务器。

由于NuGet图库使用的是entityframework 6,我正尝试按照以下步骤迁移到mysql:

1。将web.config的connectionString替换为以下

<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 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。将 EntitiesContext SupportRequestDbContext

[DbConfigurationType(typeof(EntitiesConfiguration))]替换为[DbConfigurationType(typeof(MySqlEFConfiguration))]

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连接)         在System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection连接)         在System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices,DbConnection连接)         在System.Data.Entity.Infrastructure.DefaultManifestTokenResolver。<> c__DisplayClass1.b__0(Tuple 3 k) 在 System.Collections.Concurrent.ConcurrentDictionary 2.GetOrAdd(TKey键,Func 2 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.RetryLazy 2.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(字符串connectionString,布尔型只读)位置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

0 个答案:

没有答案