I git clone the Nuget Gallery, and it's based on the sql server.
As the NuGet gallery use the entityframework 6, I was trying to migrate to the mysql following the below steps:
1.Replace the connectionStrings of web.config with below
<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.Replace the entityframework section with below:
<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.Replace [DbConfigurationType(typeof(EntitiesConfiguration))] with [DbConfigurationType(typeof(MySqlEFConfiguration))]
for EntitiesContext and SupportRequestDbContext
4.Replace the EntitiesConfiguration() constrcutor with
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());
}
But, get no luck!
When I execute Update-Database -ConfigurationTypeName MigrationsConfiguration -Verbose, it raised an exception as below:
Using StartUp project 'NuGetGallery'. Using NuGet project 'NuGetGallery'. Specify the '-Verbose' flag to view the SQL statements being applied to the target database. 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 connection) 在 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 input) 在 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