我正在尝试使用C#表单应用程序。 İ想要创建mysql数据库 在我的应用程序中使用EntityFramework Codefirst。
我的DbContext.cs文件
using MySql.Data.Entity;
using System.Data.Entity;
namespace try.DatabaseContext
{
[DbConfigurationType(typeof(MySqlEFConfiguration))]
class DatabaseContext :DbContext
{
public DatabaseContext():base("MySQL")
{
}
public DbSet<User> UserList { get; set; }
public DbSet<Roles> RoleList { get; set; }
}
}
我的AppConfig.cs文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="MySQL" connectionString="Server=localhost;Port=3306;Database=DB;Uid=root;Pwd=mypass;sslmode=None;" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<entityFramework>
<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" />
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider></providers>
</entityFramework>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.9.12.0" newVersion="6.9.12.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.data>
<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.9.12.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data></configuration>
我的packages.config文件
<packages>
<package id="EntityFramework" version="6.2.0" targetFramework="net461" />
<package id="Google.Protobuf" version="3.5.1" targetFramework="net461" />
<package id="MySql.Data" version="6.9.12" targetFramework="net461" />
<package id="MySql.Data.Entities" version="6.8.3.0" targetFramework="net461" />
<package id="MySql.Data.Entity" version="6.9.10" targetFramework="net461" />
</packages>
当我将此命令写入nugget-console
时Enable-Migrations
我得到了这个例外
'System.Data.Entity.Migrations.DbMigrationsConfiguration`1'的类型初始值设定项引发异常。