//[InlineData(DbServer.Sqlite)]
        public async Task BulkInsertOrUpdate_EntityWithNestedObjectGraph_SavesGraphToDatabase(DbServer dbServer)
        {
            ContextUtil.DbServer = dbServer;

            using var db = new GraphDbContext(ContextUtil.GetOptions <GraphDbContext>(databaseName: $"{nameof(EFCoreBulkTest)}_Graph"));
            await db.Database.EnsureCreatedAsync();

            // To ensure there are no stack overflows with circular reference trees, we must test for that.
            // Set all navigation properties so the base navigation and its inverse both have values
            foreach (var wos in WorkOrder1.WorkOrderSpares)
            {
                wos.WorkOrder = WorkOrder1;
            }

            foreach (var wos in WorkOrder2.WorkOrderSpares)
            {
                wos.WorkOrder = WorkOrder2;
            }

            WorkOrder1.Asset.WorkOrders.Add(WorkOrder1);
            WorkOrder2.Asset.WorkOrders.Add(WorkOrder2);

            WorkOrder1.Asset.ParentAsset = WorkOrder2.Asset;
            WorkOrder2.Asset.ChildAssets.Add(WorkOrder1.Asset);

            var testData = this.GetTestData(db).ToList();
            await db.BulkInsertOrUpdateAsync(testData, new BulkConfig
            {
                IncludeGraph = true
            });

            var workOrderQuery = db.WorkOrderSpares
                                 .Include(y => y.WorkOrder)
                                 .Include(y => y.WorkOrder.Asset)
                                 .Include(y => y.Spare);

            foreach (var wos in workOrderQuery)
            {
                Assert.NotNull(wos.WorkOrder);
                Assert.NotNull(wos.WorkOrder.Asset);
                Assert.NotNull(wos.Spare);
            }
        }
Esempio n. 2
0
        //[InlineData(DbServer.Sqlite)]
        public async Task BulkInsertOrUpdate_EntityWithNestedObjectGraph_SavesGraphToDatabase(DbServer dbServer)
        {
            ContextUtil.DbServer = dbServer;

            using var db = new GraphDbContext(ContextUtil.GetOptions <GraphDbContext>(databaseName: $"{nameof(EFCoreBulkTest)}_Graph"));

            var testData = this.GetTestData(db).ToList();
            await db.BulkInsertOrUpdateAsync(testData, new BulkConfig
            {
                IncludeGraph = true
            });

            var workOrderQuery = db.WorkOrderSpares
                                 .Include(y => y.WorkOrder)
                                 .Include(y => y.WorkOrder.Asset)
                                 .Include(y => y.Spare);

            foreach (var wos in workOrderQuery)
            {
                Assert.NotNull(wos.WorkOrder);
                Assert.NotNull(wos.WorkOrder.Asset);
                Assert.NotNull(wos.Spare);
            }
        }