示例#1
0
        public static IEnumerable <IEntityType> GetEntityTypes()
        {
            IEnumerable <IEntityType> entityTypes;

            using (var context = new AuditorDbContext(ContextProvider.ContextOptions))
            {
                entityTypes = context.Model.GetEntityTypes();
            }

            return(entityTypes);
        }
示例#2
0
        public static async Task Ensure()
        {
            ContextProvider.SetContextOptions();
            Console.WriteLine($"Connecting database to: {ContextProvider.ConnectionString}");

            using (var context = new AuditorDbContext(ContextProvider.ContextOptions))
            {
                Console.WriteLine($"Ensuring database...");

                try
                {
                    await context.Database.MigrateAsync();

                    await context.Database.EnsureCreatedAsync();
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Connection string is not valid. Please check the connection string at appsettings.json, then try again");
                    throw;
                }

                Console.WriteLine($"Database confirmed...");
            }
        }