예제 #1
0
파일: Program.cs 프로젝트: uopeydel/testdb
        public static async Task SeedAsync(FCDbContext context)
        {
            //var context = serviceProvider.GetRequiredService<YourDbContext>();
            context.Database.EnsureCreated();

            var taxonomySeed = new List <Taxonomy>
            {
                new Taxonomy
                {
                    Id    = 1,
                    Key   = "DC1",
                    Value = "abcx"
                },
                new Taxonomy
                {
                    Id    = 2,
                    Key   = "DC2",
                    Value = "abcy"
                },
                new Taxonomy
                {
                    Id    = 3,
                    Key   = "DC3",
                    Value = "abcz"
                },
            };
            var masterData = await context.Taxonomy.ToListAsync();

            var removeList = masterData.Where(w => !taxonomySeed.Contains(w)).ToList();

            if (removeList.Any())
            {
                context.RemoveRange(removeList);
            }
            var addList = taxonomySeed.Where(w => !masterData.Contains(w)).ToList();
            await context.AddRangeAsync(addList);

            await context.SaveChangesAsync();

            await SeedMaster(context);
        }
예제 #2
0
파일: Program.cs 프로젝트: uopeydel/testdb
        private static async Task SeedMaster(FCDbContext context)
        {
            var masterSeed = new List <Master>
            {
                new Master
                {
                    Id         = 1,
                    Key        = "MS1",
                    Value      = "wweee1",
                    TaxonomyId = 1
                },
                new Master
                {
                    Id         = 2,
                    Key        = "MS2",
                    Value      = "qqrrr2",
                    TaxonomyId = 2,
                },
                new Master
                {
                    Id         = 3,
                    Key        = "MS3",
                    Value      = "zzcc3",
                    TaxonomyId = 3,
                },
            };
            var masterData = await context.Master.ToListAsync();

            var removeList = masterData.Where(w => !masterSeed.Contains(w)).ToList();

            if (removeList.Any())
            {
                context.RemoveRange(removeList);
            }
            var addList = masterSeed.Where(w => !masterData.Contains(w)).ToList();
            await context.AddRangeAsync(addList);

            await context.SaveChangesAsync();
        }
예제 #3
0
파일: Startup.cs 프로젝트: uopeydel/testdb
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app, IWebHostEnvironment env, FCDbContext db)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            //db.Database.Migrate();

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }