当我运行启用迁移时显示错误!我做了SQLServer的逆向工程,我想在我的Data上做一些更换器我看到这个错误引导我到config.cs上的第10行,它是visual studio(iam使用Visual 2015)生成的构造函数,sql connector 6.9 .4
Checking if the context targets an existing database...
System.TypeInitializationException: The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception. ---> System.TypeLoadException: Inheritance security rules violated by type: 'MySql.Data.Entity.MySqlEFConfiguration'. Derived types must either match the security accessibility of the base type or be less accessible.
at System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule, IRuntimeMethodInfo pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
at System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule module, IRuntimeMethodInfo ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
at System.RuntimeType.GetCustomAttributes(Type attributeType, Boolean inherit)
at System.Attribute.GetCustomAttributes(MemberInfo element, Type type, Boolean inherit)
at System.Reflection.CustomAttributeExtensions.GetCustomAttributes[T](MemberInfo element, Boolean inherit)
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationFinder.TryFindConfigurationType(Assembly assemblyHint, Type contextTypeHint, IEnumerable`1 typesToSearch)
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForAssembly(Assembly assemblyHint, Type contextTypeHint)
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForContext(Type contextType)
at System.Data.Entity.Migrations.DbMigrationsConfiguration`1..cctor()
--- End of inner exception stack trace ---
at System.Data.Entity.Migrations.DbMigrationsConfiguration`1..ctor()
at Data.Migrations.Configuration..ctor() in C:\Users\saif kouti\Desktop\piski[pi_kouti]\piski\Data\Migrations\Configuration.cs:line 10
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Data.Entity.Migrations.Utilities.MigrationsConfigurationFinder.FindMigrationsConfiguration(Type contextType, String configurationTypeName, Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName)
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration()
at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception.
这里是我的configuation.cs
namespace Data.Migrations
{
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
internal sealed class Configuration : DbMigrationsConfiguration<iskiContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
}
protected override void Seed(Data.iskiContext context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data.
}
}
}
和我的上下文
using System.Data.Entity;
using Domain.Models.Mapping;
using Domain.Models;
namespace Data
{
[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public partial class iskiContext : DbContext
{
static iskiContext()
{
Database.SetInitializer<iskiContext>(null);
}
public iskiContext()
: base("Name=iskiContext")
{
}
public DbSet<accomodation> accomodations { get; set; }
public DbSet<company> companies { get; set; }
public DbSet<contract> contracts { get; set; }
public DbSet<Event> events { get; set; }
public DbSet<event_user> event_user { get; set; }
public DbSet<organizerrequest> organizerrequests { get; set; }
public DbSet<product> products { get; set; }
public DbSet<products_user> products_user { get; set; }
public DbSet<user> users { get; set; }
public DbSet<user_company> user_company { get; set; }
public DbSet<winner> winners { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new accomodationMap());
modelBuilder.Configurations.Add(new companyMap());
modelBuilder.Configurations.Add(new contractMap());
modelBuilder.Configurations.Add(new eventMap());
modelBuilder.Configurations.Add(new event_userMap());
modelBuilder.Configurations.Add(new organizerrequestMap());
modelBuilder.Configurations.Add(new productMap());
modelBuilder.Configurations.Add(new products_userMap());
modelBuilder.Configurations.Add(new userMap());
modelBuilder.Configurations.Add(new user_companyMap());
modelBuilder.Configurations.Add(new winnerMap());
}
}
}
答案 0 :(得分:0)
检查迁移文件中的up()和down()方法。根据此上下功能,您的更改将在update-database
命令后提交。
否则你的AutomaticMigrationsEnabled = true