private static void Init() { using (var db = new woodmanContext()) { var entities = db.EfCoreTest.Where(e => e.Name.Contains(nameof(BulkTransactionTests))).ToList(); if (entities.Count > 0) { db.RemoveRange(entities); } for (var i = 0; i < InitialCount; i++) { db.Add(new EfCoreTest { Name = nameof(BulkTransactionTests), CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }); } db.SaveChanges(); } using (var db = new postgresContext()) { var entities = db.Efcoretest.Where(e => e.Name.Contains(nameof(BulkTransactionTests))).ToList(); if (entities.Count > 0) { db.RemoveRange(entities); } for (var i = 0; i < InitialCount; i++) { db.Add(new Efcoretest { Name = nameof(BulkTransactionTests), Createddate = DateTime.Now, Modifieddate = DateTime.Now }); } db.SaveChanges(); } }
protected virtual void InitiEfCoreTestNonValueTypeKeys(woodmanContext db, int iteration) { var name = $"{Name}_{iteration}"; var existing = db.EfCoreTestNonValueTypeKeys .Where(e => e.Name == name) .FirstOrDefault(); if (existing == null) { var inserted = db.Add(new EfCoreTestNonValueTypeKeys { Tier1Id = Guid.NewGuid().ToString(), Tier2Id = Guid.NewGuid().ToString(), Name = name, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsArchived = false }); db.SaveChanges(); } }
protected virtual void InitSqlDb() { using (var db = new woodmanContext()) { for (var i = 1; i <= 10; i++) { var name = $"{Name}_{i}"; int efCoreTestId; InitiEfCoreTestNonValueTypeKeys(db, i); var existing = db.EfCoreTest .Where(e => e.Name == name) .FirstOrDefault(); if (existing == null) { var inserted = db.Add(new EfCoreTest { Name = name, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }); db.SaveChanges(); efCoreTestId = inserted.Entity.Id; SqlIds.Add(inserted.Entity.Id); } else { efCoreTestId = existing.Id; SqlIds.Add(existing.Id); } if (i > 5) { continue; } for (var j = 1; j <= 4; j++) { var childName = $"{Name}_{i}_{j}"; var existingChild = db.EfCoreTestChild .Where(e => e.Name == childName) .FirstOrDefault(); if (existingChild == null) { var inserted = db.Add(new EfCoreTestChild { EfCoreTestId = efCoreTestId, Name = name, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }); db.SaveChanges(); SqlCompositeIds.Add(new object[] { inserted.Entity.Id, efCoreTestId }); } else { SqlCompositeIds.Add(new object[] { existing.Id, efCoreTestId }); } } } } }