Exemplo n.º 1
0
        public static IEnumerable <EntityTypeConfiguration> DerivedTypes(this ODataModelBuilder modelBuilder,
                                                                         EntityTypeConfiguration entity)
        {
            if (modelBuilder == null)
            {
                throw Error.ArgumentNull("modelBuilder");
            }

            if (entity == null)
            {
                throw Error.ArgumentNull("entity");
            }

            IEnumerable <EntityTypeConfiguration> derivedEntities = modelBuilder.StructuralTypes
                                                                    .OfType <EntityTypeConfiguration>().Where(e => e.BaseType == entity);

            foreach (EntityTypeConfiguration derivedType in derivedEntities)
            {
                yield return(derivedType);

                foreach (EntityTypeConfiguration derivedDerivedType in modelBuilder.DerivedTypes(derivedType))
                {
                    yield return(derivedDerivedType);
                }
            }
        }
Exemplo n.º 2
0
        public static IEnumerable <ComplexTypeConfiguration> DerivedTypes(this ODataModelBuilder modelBuilder,
                                                                          ComplexTypeConfiguration complex)
        {
            if (modelBuilder == null)
            {
                throw Error.ArgumentNull("modelBuilder");
            }

            if (complex == null)
            {
                throw Error.ArgumentNull("complex");
            }

            IEnumerable <ComplexTypeConfiguration> derivedComplexs =
                modelBuilder.StructuralTypes.OfType <ComplexTypeConfiguration>().Where(e => e.BaseType == complex);

            foreach (ComplexTypeConfiguration derivedType in derivedComplexs)
            {
                yield return(derivedType);

                foreach (ComplexTypeConfiguration derivedDerivedType in modelBuilder.DerivedTypes(derivedType))
                {
                    yield return(derivedDerivedType);
                }
            }
        }
        // Returns the base types, this type and all the derived types of this type.
        public static IEnumerable <EntityTypeConfiguration> ThisAndBaseAndDerivedTypes(this ODataModelBuilder modelBuilder, EntityTypeConfiguration entity)
        {
            Contract.Assert(modelBuilder != null);
            Contract.Assert(entity != null);

            return(entity.BaseTypes()
                   .Concat(new[] { entity })
                   .Concat(modelBuilder.DerivedTypes(entity)));
        }
Exemplo n.º 4
0
        // Returns the base types, this type and all the derived types of this type.
        public static IEnumerable <StructuralTypeConfiguration> ThisAndBaseAndDerivedTypes(
            this ODataModelBuilder modelBuilder, StructuralTypeConfiguration structuralType)
        {
            Contract.Assert(modelBuilder != null);
            Contract.Assert(structuralType != null);

            return(structuralType.BaseTypes()
                   .Concat(new[] { structuralType })
                   .Concat(modelBuilder.DerivedTypes(structuralType)));
        }
        public void DerivedTypes_Works()
        {
            ODataModelBuilder       builder    = GetMockVehicleModel();
            EntityTypeConfiguration vehicle    = builder.StructuralTypes.OfType <EntityTypeConfiguration>().Where(e => e.Name == "vehicle").Single();
            EntityTypeConfiguration car        = builder.StructuralTypes.OfType <EntityTypeConfiguration>().Where(e => e.Name == "car").Single();
            EntityTypeConfiguration motorcycle = builder.StructuralTypes.OfType <EntityTypeConfiguration>().Where(e => e.Name == "motorcycle").Single();
            EntityTypeConfiguration sportbike  = builder.StructuralTypes.OfType <EntityTypeConfiguration>().Where(e => e.Name == "sportbike").Single();

            Assert.Equal(
                builder.DerivedTypes(vehicle).Select(e => e.Name).OrderBy(name => name),
                new[] { sportbike, motorcycle, car }.Select(e => e.Name).OrderBy(name => name));
        }
        public void ComplexType_DerivedTypes_Works()
        {
            // Arrange
            ODataModelBuilder builder = GetMockVehicleModel();

            ComplexTypeConfiguration address = builder.StructuralTypes
                                               .OfType <ComplexTypeConfiguration>().Single(e => e.Name == "Address");

            // Act & Assert
            Assert.Equal(
                new[] { "CarAddress", "MotorcycleAddress", "SportbikeAddress" }.OrderBy(name => name),
                builder.DerivedTypes(address).Select(e => e.Name).OrderBy(name => name));
        }
        public void EntityType_DerivedTypes_Works()
        {
            // Arrange
            ODataModelBuilder builder = GetMockVehicleModel();

            EntityTypeConfiguration vehicle = builder.StructuralTypes
                                              .OfType <EntityTypeConfiguration>().Single(e => e.Name == "vehicle");

            // Act & Assert
            Assert.Equal(
                new[] { "car", "motorcycle", "sportbike" }.OrderBy(name => name),
                builder.DerivedTypes(vehicle).Select(e => e.Name).OrderBy(name => name));
        }
Exemplo n.º 8
0
        public static void FindAllNavigationProperties(this ODataModelBuilder builder,
                                                       StructuralTypeConfiguration configuration,
                                                       IList <Tuple <StructuralTypeConfiguration, IList <MemberInfo>, NavigationPropertyConfiguration> > navigations,
                                                       Stack <MemberInfo> path)
        {
            if (builder == null)
            {
                throw Error.ArgumentNull("builder");
            }

            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            if (navigations == null)
            {
                throw Error.ArgumentNull("navigations");
            }

            if (path == null)
            {
                throw Error.ArgumentNull("path");
            }

            IEnumerable <StructuralTypeConfiguration> thisAndBaseTypes = configuration.ThisAndBaseTypes();

            foreach (var config in thisAndBaseTypes)
            {
                builder.FindNavigationProperties(config, navigations, path);
            }

            IEnumerable <StructuralTypeConfiguration> derivedTypes = builder.DerivedTypes(configuration);

            foreach (var config in derivedTypes)
            {
                if (path.OfType <Type>().Any(p => p == config.ClrType))
                {
                    continue;
                }

                path.Push(config.ClrType);

                builder.FindNavigationProperties(config, navigations, path);

                path.Pop();
            }
        }