示例#1
0
        private static void Init()
        {
            using (var db = new woodmanContext())
            {
                var childEntities = db.EfCoreTestChild
                                    .Where(e => e.Name == null || e.Name.Contains(nameof(BulkAddTests)))
                                    .ToList();

                if (childEntities.Count > 0)
                {
                    db.RemoveRange(childEntities);
                    db.SaveChanges();
                }

                var entities = db.EfCoreTest
                               .Where(e => e.Name == null || e.Name.Contains(nameof(BulkAddTests)))
                               .ToList();

                if (entities.Count > 0)
                {
                    db.RemoveRange(entities);
                    db.SaveChanges();
                }
            }

            using (var db = new postgresContext())
            {
                var childEntities = db.Efcoretestchild
                                    .Where(e => e.Name == null || e.Name.Contains(nameof(BulkAddTests)))
                                    .ToList();

                if (childEntities.Count > 0)
                {
                    db.RemoveRange(childEntities);
                    db.SaveChanges();
                }

                var entities = db.Efcoretest
                               .Where(e => e.Name == null || e.Name.Contains(nameof(BulkAddTests)))
                               .ToList();

                if (entities.Count > 0)
                {
                    db.RemoveRange(entities);
                    db.SaveChanges();
                }
            }
        }
示例#2
0
        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();
            }
        }