private static DbContextInitializerBase CreateInitializer() { DbContextInitializerBase initializer = new DefaultDbContextInitializer() as DbContextInitializerBase; //if (initializer == null) //{ // throw new InvalidOperationException("类型“{0}”不是有效的上下文初始化类型"); //} //ICollection<Assembly> EntityMapperAssemblies = null; //string[] mapperFiles = "ls.context".Split(','); //var a = mapperFiles.Select(fileName => fileName.EndsWith(".dll") ? fileName : fileName + ".dll"); //var b = a.Select(fileName => Path.Combine(AppDomain.CurrentDomain.RelativeSearchPath, fileName)).ToArray(); //EntityMapperAssemblies = //b.Select(Assembly.LoadFrom).ToList(); //var a = AppDomain.CurrentDomain.GetAssemblies(); //var b = a.SelectMany(assembly => assembly.GetTypes().Where(type => typeof(IEntityMapper).IsAssignableFrom(type) && !type.IsAbstract)); //EntityMapperAssemblies = b.Select(Assembly.LoadFrom).ToList(); //foreach (Assembly mapperAssembly in EntityMapperAssemblies) //{ // if (initializer.MapperAssemblies.Contains(mapperAssembly)) // { // continue; // } // initializer.MapperAssemblies.Add(mapperAssembly); //} return(initializer); }
private static DbContextInitializerBase CreateInitializer() { DbContextInitializerBase initializer = new DefaultDbContextInitializer() as DbContextInitializerBase; //if (initializer == null) //{ // throw new InvalidOperationException("类型“{0}”不是有效的上下文初始化类型"); //} //ICollection<Assembly> EntityMapperAssemblies = null; //string[] mapperFiles = "ls.context".Split(','); //var a = mapperFiles.Select(fileName => fileName.EndsWith(".dll") ? fileName : fileName + ".dll"); //var b = a.Select(fileName => Path.Combine(AppDomain.CurrentDomain.RelativeSearchPath, fileName)).ToArray(); //EntityMapperAssemblies = //b.Select(Assembly.LoadFrom).ToList(); //var a = AppDomain.CurrentDomain.GetAssemblies(); //var b = a.SelectMany(assembly => assembly.GetTypes().Where(type => typeof(IEntityMapper).IsAssignableFrom(type) && !type.IsAbstract)); //EntityMapperAssemblies = b.Select(Assembly.LoadFrom).ToList(); //foreach (Assembly mapperAssembly in EntityMapperAssemblies) //{ // if (initializer.MapperAssemblies.Contains(mapperAssembly)) // { // continue; // } // initializer.MapperAssemblies.Add(mapperAssembly); //} return initializer; }