Example #1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new CompanyStructureContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <CompanyStructureContext> >()))
            {
                if (!context.Companies.Any())
                {
                    var rootId    = Guid.NewGuid();
                    var idb       = Guid.NewGuid();
                    var companies = new List <Company>()
                    {
                        new Company {
                            Name = "A", ParentId = null, ExternalId = rootId
                        },
                        new Company {
                            Name = "B", ParentId = rootId, ExternalId = idb
                        },
                        new Company {
                            Name = "C", ParentId = rootId, ExternalId = Guid.NewGuid()
                        },
                        new Company {
                            Name = "E", ParentId = idb, ExternalId = Guid.NewGuid()
                        },
                        new Company {
                            Name = "F", ParentId = idb, ExternalId = Guid.NewGuid()
                        }
                    };

                    context.Companies.AddRange(companies);
                    context.SaveChanges();
                    context.Dispose();
                }
            }
        }
Example #2
0
 public CompanyRepository(CompanyStructureContext dbContext)
     : base(dbContext)
 {
 }
Example #3
0
 public RepositoryBase(CompanyStructureContext dbContext)
 {
     _dbContext = dbContext;
 }