Home can not Enable Migrations
Reply: 1

can not Enable Migrations

Saif Kouti SaifKouti
1#
Saif Kouti SaifKouti Published in 2017-11-14 13:12:45Z

That error show when i run Enable Migration ! iam did the reverse engineering the SQLServer and i want to do some changers on my Data i see this erroe whoch guide me to the line 10 on config.cs which is the constructor generated by visual studio (iam using 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.

here my 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.
        }
    }
}

and here my context

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());
        }
    }
}
Tazbirul Haque
2#
Tazbirul Haque Reply to 2017-11-14 19:56:42Z

check the up() and down() methods in your migration file. Your changes will be submitted after update-databasecommand according to this up and down function. otherwise make your AutomaticMigrationsEnabled = true

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30907 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO