Ejemplo n.º 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();
                }
            }
        }
Ejemplo n.º 2
0
 public void Update(TEntity entity)
 {
     _dbContext.Set <TEntity>().Update(entity);
     _dbContext.SaveChanges();
 }