Пример #1
0
        public static void SeedData(CommanderContext Context)
        {
            System.Console.WriteLine("Applying Migrations...");

            Context.Database.Migrate();

            if (!Context.Commands.Any())
            {
                System.Console.WriteLine("Seeding data...");

                Context.Commands.AddRange(
                    new Command()
                {
                    HowTo = "HowTo1", Line = "Line1", Platform = "Platform1"
                },
                    new Command()
                {
                    HowTo = "HowTo2", Line = "Line2", Platform = "Platform2"
                },
                    new Command()
                {
                    HowTo = "HowTo3", Line = "Line3", Platform = "Platform3"
                }
                    );

                Context.SaveChanges();
            }
            else
            {
                System.Console.WriteLine("Data already exists. Skip Seeding data...");
            }
        }
Пример #2
0
 public bool SaveChanges()
 {
     return(_context.SaveChanges() >= 0);
     // whenever you make a change to dbcontext, the data would be changed on database
     // unless we call this method, we're gonna use create/add but until we call "SaveChanges"
     // that won't be implemented in the database!
 }
Пример #3
0
        private static void SeedData(CommanderContext context)
        {
            Console.WriteLine("Appling migrations ...");
            context.Database.Migrate();

            if (!context.Commands.Any())
            {
                Console.WriteLine("Adding data - seeding ...");
                context.Commands.AddRange(
                    new Command {
                    HowTo = "How to 1", Line = "Line 1", Platform = "Platform 1"
                },
                    new Command {
                    HowTo = "How to 2", Line = "Line 2", Platform = "Platform 2"
                },
                    new Command {
                    HowTo = "How to 3", Line = "Line 3", Platform = "Platform 3"
                },
                    new Command {
                    HowTo = "How to 4", Line = "Line 4", Platform = "Platform 4"
                }
                    );

                context.SaveChanges();
            }
            else
            {
                Console.WriteLine("Already have data - not seeding");
            }
        }
Пример #4
0
        private void Seed()
        {
            using (var context = new CommanderContext(ContextOptions))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                var cmd = new Command {
                    HowTo = "Test create command", Line = "Test line", Platform = "test"
                };

                context.Add(cmd);

                context.SaveChanges();
            }
        }
Пример #5
0
        public static void SeedData(CommanderContext context)
        {
            System.Console.WriteLine("Applying Migrations...");

            context.Database.Migrate();

            if (!context.Commands.Any())
            {
                System.Console.WriteLine("Adding data - seeding...");
                context.Commands.AddRange(
                    new Command()
                {
                    HowTo = "foobar", Line = "foobar1", Platform = "foobar2"
                }

                    );
                context.SaveChanges();
            }
            else
            {
                System.Console.WriteLine("Already have data - not seeding");
            }
        }
 public bool SaveChanges()
 {
     return(_context.SaveChanges() >= 0);
 }
Пример #7
0
 public void Dispose()
 {
     _optionsBuilder = null;
     foreach (var cmd in _dbContext.Commands)
     {
         _dbContext.Commands.Remove(cmd);
     }
     _dbContext.SaveChanges();
     _dbContext.Dispose();
     _mapper        = null;
     _commanderRepo = null;
     _controller    = null;
 }