コード例 #1
0
        /// <summary>
        /// The initialize.
        /// </summary>
        /// <param name="applyEFHack">
        /// apply the EF hack.
        /// </param>
        /// <param name="supportExplicitConnectionStrings">
        /// The support explicit connection strings.
        /// </param>
        private static void Initialize(bool applyEFHack, bool supportExplicitConnectionStrings)
        {
            if (supportExplicitConnectionStrings && (applyEFHack || IsEF41HackRequired()))
            {
                EFProviderUtilities.UseEF41Hack();
            }

            InitializeDbProviderFactories();

            ExcludeEntityFrameworkAssemblies();
        }
コード例 #2
0
        /// <summary>
        /// The initialize database provider factories.
        /// </summary>
        private static void InitializeDbProviderFactories()
        {
            try
            {
                // ensure all the factories are loaded
                DbProviderFactories.GetFactoryClasses();
            }
            catch (ArgumentException)
            {
            }

            Type type = typeof(DbProviderFactories);

            DataTable table      = null;
            object    setOrTable = (type.GetField("_configTable", BindingFlags.NonPublic | BindingFlags.Static) ??
                                    type.GetField("_providerTable", BindingFlags.NonPublic | BindingFlags.Static)).GetValue(null);

            var set = setOrTable as DataSet;

            if (set != null)
            {
                table = set.Tables["DbProviderFactories"];
            }

            table = (DataTable)setOrTable;

            foreach (DataRow row in table.Rows.Cast <DataRow>().ToList())
            {
                DbProviderFactory factory;
                try
                {
                    factory = DbProviderFactories.GetFactory(row);
                }
                catch (Exception)
                {
                    continue;
                }

                var profType = EFProviderUtilities.ResolveFactoryType(factory.GetType());
                if (profType != null)
                {
                    DataRow profiled = table.NewRow();
                    profiled["Name"]                  = row["Name"];
                    profiled["Description"]           = row["Description"];
                    profiled["InvariantName"]         = row["InvariantName"];
                    profiled["AssemblyQualifiedName"] = profType.AssemblyQualifiedName;
                    table.Rows.Remove(row);
                    table.Rows.Add(profiled);
                }
            }
        }