Example #1
0
        public static ConventionSet Build()
        {
            var serviceProvider = new ServiceCollection()
                                  .AddEntityFrameworkOracle()
                                  .AddDbContext <DbContext>(o => o.UseOracle("Data Source=."))
                                  .BuildServiceProvider();

            using (var serviceScope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope()) {
                using (var context = serviceScope.ServiceProvider.GetService <DbContext>()) {
                    return(ConventionSet.CreateConventionSet(context));
                }
            }
        }
        /// <summary>
        ///     <para>
        ///         Call this method to build a <see cref="ConventionSet" /> for SQL Server when using
        ///         the <see cref="ModelBuilder" /> outside of <see cref="DbContext.OnModelCreating" />.
        ///     </para>
        ///     <para>
        ///         Note that it is unusual to use this method.
        ///         Consider using <see cref="DbContext" /> in the normal way instead.
        ///     </para>
        /// </summary>
        /// <returns> The convention set. </returns>
        public static ConventionSet Build()
        {
            var serviceProvider = new ServiceCollection()
                                  .AddEntityFrameworkSqlServer()
                                  .AddDbContext <DbContext>(
                (p, o) =>
                o.UseSqlServer("Server=.")
                .UseInternalServiceProvider(p))
                                  .BuildServiceProvider();

            using var serviceScope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope();
            using var context      = serviceScope.ServiceProvider.GetService <DbContext>();
            return(ConventionSet.CreateConventionSet(context));
        }
Example #3
0
        public static ConventionSet Build()
        {
            var serviceProvider = new ServiceCollection()
                                  .AddEntityFrameworkJet()
                                  .AddDbContext <DbContext>((p, o) => o
                                                            .UseJetWithoutPredefinedDataAccessProvider(
                                                                JetConnection.GetConnectionString("Jet.accdb", DataAccessProviderType.Odbc))
                                                            .UseInternalServiceProvider(p))
                                  .BuildServiceProvider();

            using var serviceScope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope();
            using var context      = serviceScope.ServiceProvider.GetService <DbContext>();
            return(ConventionSet.CreateConventionSet(context));
        }
        /// <summary>
        ///     <para>
        ///         Call this method to build a <see cref="ConventionSet" /> for MySQL when using
        ///         the <see cref="ModelBuilder" /> outside of <see cref="DbContext.OnModelCreating" />.
        ///     </para>
        ///     <para>
        ///         Note that it is unusual to use this method.
        ///         Consider using <see cref="DbContext" /> in the normal way instead.
        ///     </para>
        /// </summary>
        /// <returns> The convention set. </returns>
        public static ConventionSet Build()
        {
            var serviceProvider = new ServiceCollection()
                                  .AddEntityFrameworkMySql()
                                  .AddDbContext <DbContext>(o => o.UseMySql("Server=.", MySqlServerVersion.LatestSupportedServerVersion))
                                  .BuildServiceProvider();

            using (var serviceScope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                using (var context = serviceScope.ServiceProvider.GetService <DbContext>())
                {
                    return(ConventionSet.CreateConventionSet(context));
                }
            }
        }
Example #5
0
 /// <summary>
 ///     <para>
 ///         Call this method to build a <see cref="ModelBuilder" /> for SQL Server outside of <see cref="DbContext.OnModelCreating" />.
 ///     </para>
 ///     <para>
 ///         Note that it is unusual to use this method.
 ///         Consider using <see cref="DbContext" /> in the normal way instead.
 ///     </para>
 /// </summary>
 /// <returns> The convention set. </returns>
 public static ModelBuilder CreateModelBuilder()
 {
     using var serviceScope = CreateServiceScope();
     using var context      = serviceScope.ServiceProvider.GetService <DbContext>();
     return(new ModelBuilder(ConventionSet.CreateConventionSet(context), context.GetService <ModelDependencies>()));
 }
Example #6
0
 /// <summary>
 ///     <para>
 ///         Call this method to build a <see cref="ConventionSet" /> for SQL Server when using
 ///         the <see cref="ModelBuilder" /> outside of <see cref="DbContext.OnModelCreating" />.
 ///     </para>
 ///     <para>
 ///         Note that it is unusual to use this method.
 ///         Consider using <see cref="DbContext" /> in the normal way instead.
 ///     </para>
 /// </summary>
 /// <returns> The convention set. </returns>
 public static ConventionSet Build()
 {
     using var serviceScope = CreateServiceScope();
     using var context      = serviceScope.ServiceProvider.GetService <DbContext>();
     return(ConventionSet.CreateConventionSet(context));
 }