Ejemplo n.º 1
0
        public void Setup()
        {
            if (Context != null)
            {
                return;
            }
            var serviceProvider = new ServiceCollection()
                                  .AddEntityFrameworkSqlServer()
                                  .BuildServiceProvider();

            var builder = new DbContextOptionsBuilder <ZwinnyCRUDCloudContext>();

            builder.UseSqlServer($"Server=(localdb)\\mssqllocaldb;Database=ZwinnyCRUDCloudContext-{Guid.NewGuid()};Trusted_Connection=True;MultipleActiveResultSets=true")
            .UseInternalServiceProvider(serviceProvider);

            Context = new ZwinnyCRUDCloudContext(builder.Options);
            Context.Database.Migrate();
        }
Ejemplo n.º 2
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new ZwinnyCRUDCloudContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <ZwinnyCRUDCloudContext> >()))
            {
                context.Database.Migrate();
                if (context.Project.Any())
                {
                    return;   // DB has been seeded
                }

                context.Project.AddRange(
                    new Project
                {
                    Title        = "GitHub Notifier",
                    Description  = "Listen for events from GitHub and notify you.",
                    CreationDate = DateTime.Parse("2020-10-12")
                },

                    new Project
                {
                    Title        = "Food log",
                    Description  = "Keep track of everything you eat with a simple submission form.",
                    CreationDate = DateTime.Parse("2020-10-29")
                },

                    new Project
                {
                    Title        = "RSS aggregator",
                    Description  = "Poll RSS feeds for new articles and make a new feed that combines them.",
                    CreationDate = DateTime.Parse("2020-11-16")
                },

                    new Project
                {
                    Title        = "Weather App",
                    Description  = "Use the Forecast.io api to display the weather near you.",
                    CreationDate = DateTime.Parse("2020-12-15")
                }
                    );
                context.SaveChanges();
            }
        }
 public ProjectDatabaseFromEFContext(ZwinnyCRUDCloudContext dbContext, ILogger <ProjectDatabaseFromEFContext> logger)
 {
     _context = dbContext;
     _logger  = logger;
 }
 public TaskDatabaseFromEFContext(ZwinnyCRUDCloudContext dbContext, IProjectDatabase projectContext, ILogger <TaskDatabaseFromEFContext> logger)
 {
     _context        = dbContext;
     _projectContext = projectContext;
     _logger         = logger;
 }
Ejemplo n.º 5
0
 public FileDatabaseFromEFContext(ZwinnyCRUDCloudContext dbContext)
 {
     _context = dbContext;
 }