コード例 #1
0
#pragma warning disable EF1001 // Internal EF Core API usage.
        // Issue #16707
        private IUpdateEntry GetRootDocument(InternalEntityEntry entry)
        {
            var stateManager = entry.StateManager;
            var ownership    = entry.EntityType.FindOwnership();
            var principal    = stateManager.FindPrincipal(entry, ownership);

            if (principal == null)
            {
                if (_sensitiveLoggingEnabled)
                {
                    throw new InvalidOperationException(
                              CosmosStrings.OrphanedNestedDocumentSensitive(
                                  entry.EntityType.DisplayName(),
                                  ownership.PrincipalEntityType.DisplayName(),
                                  entry.BuildCurrentValuesString(entry.EntityType.FindPrimaryKey().Properties)));
                }

                throw new InvalidOperationException(
                          CosmosStrings.OrphanedNestedDocument(
                              entry.EntityType.DisplayName(),
                              ownership.PrincipalEntityType.DisplayName()));
            }

            return(principal.EntityType.IsDocumentRoot() ? principal : GetRootDocument(principal));
        }
コード例 #2
0
        public virtual void Inserting_dependent_without_principal_throws()
        {
            using (CreateTestStore(OnModelCreating))
            {
                using (var context = CreateContext())
                {
                    context.Add(
                        new PoweredVehicle
                    {
                        Name            = "Fuel transport",
                        SeatingCapacity = 1,
                        Operator        = new LicensedOperator
                        {
                            Name        = "Jack Jackson",
                            LicenseType = "Class A CDC"
                        }
                    });
                    context.Add(
                        new FuelTank
                    {
                        Capacity    = "10000 l",
                        FuelType    = "Gas",
                        VehicleName = "Fuel transport"
                    });

                    Assert.Equal(
                        CosmosStrings.OrphanedNestedDocumentSensitive(
                            nameof(FuelTank), nameof(CombustionEngine), "{VehicleName: Fuel transport}"),
                        Assert.Throws <InvalidOperationException>(() => context.SaveChanges()).Message);
                }
            }
        }
コード例 #3
0
        public virtual async Task Inserting_dependent_without_principal_throws()
        {
            var options = Fixture.CreateOptions(seed: false);

            using (var context = new EmbeddedTransportationContext(options))
            {
                context.Add(
                    new LicensedOperator {
                    Name = "Jack Jackson", LicenseType = "Class A CDC", VehicleName = "Fuel transport"
                });

                Assert.Equal(
                    CosmosStrings.OrphanedNestedDocumentSensitive(
                        nameof(Operator), nameof(Vehicle), "{VehicleName: Fuel transport}"),
                    (await Assert.ThrowsAsync <InvalidOperationException>(() => context.SaveChangesAsync())).Message);
            }
        }
コード例 #4
0
        public virtual async Task Inserting_dependent_without_principal_throws()
        {
            await using (var testDatabase = CreateTestStore(seed: false))
            {
                using (var context = CreateContext())
                {
                    context.Add(
                        new LicensedOperator {
                        Name = "Jack Jackson", LicenseType = "Class A CDC", VehicleName = "Fuel transport"
                    });

                    Assert.Equal(
                        CosmosStrings.OrphanedNestedDocumentSensitive(
                            nameof(Operator), nameof(Vehicle), "{VehicleName: Fuel transport}"),
                        Assert.Throws <InvalidOperationException>(() => context.SaveChanges()).Message);
                }
            }
        }