예제 #1
0
파일: SeedData.cs 프로젝트: olexender/Api
        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();
                }
            }
        }
예제 #2
0
 public CompanyRepository(CompanyStructureContext dbContext)
     : base(dbContext)
 {
 }
예제 #3
0
 public RepositoryBase(CompanyStructureContext dbContext)
 {
     _dbContext = dbContext;
 }