public void ComplexType_ThisAndBaseAndDerivedTypes_Works()
        {
            // Arrange
            ODataModelBuilder        builder = GetMockVehicleModel();
            ComplexTypeConfiguration address = builder.StructuralTypes
                                               .OfType <ComplexTypeConfiguration>().Single(e => e.Name == "Address");

            // Act & Assert
            Assert.Equal(
                new[] { "Address", "CarAddress", "MotorcycleAddress", "SportbikeAddress" }.OrderBy(name => name),
                builder.ThisAndBaseAndDerivedTypes(address).Select(e => e.Name).OrderBy(name => name));
        }
        public void EntityType_ThisAndBaseAndDerivedTypes_Works()
        {
            // Arrange
            ODataModelBuilder       builder = GetMockVehicleModel();
            EntityTypeConfiguration vehicle = builder.StructuralTypes
                                              .OfType <EntityTypeConfiguration>().Single(e => e.Name == "vehicle");

            // Act & Assert
            Assert.Equal(
                new[] { "car", "motorcycle", "sportbike", "vehicle" }.OrderBy(e => e),
                builder.ThisAndBaseAndDerivedTypes(vehicle).Select(e => e.Name).OrderBy(name => name));
        }
 public void Apply(INavigationSourceConfiguration configuration, ODataModelBuilder model)
 {
     foreach (EntityTypeConfiguration entity in model.ThisAndBaseAndDerivedTypes(configuration.EntityType))
     {
         foreach (NavigationPropertyConfiguration navigationProperty in entity.NavigationProperties)
         {
             NavigationSourceConfiguration targetNavigationSource = GetTargetNavigationSource(navigationProperty, model);
             if (targetNavigationSource != null)
             {
                 configuration.AddBinding(navigationProperty, targetNavigationSource);
             }
         }
     }
 }
 public void Apply(EntitySetConfiguration configuration, ODataModelBuilder model)
 {
     foreach (EntityTypeConfiguration entity in model.ThisAndBaseAndDerivedTypes(configuration.EntityType))
     {
         foreach (NavigationPropertyConfiguration navigationProperty in entity.NavigationProperties)
         {
             EntitySetConfiguration targetEntitySet = GetTargetEntitySet(navigationProperty, model);
             if (targetEntitySet != null)
             {
                 configuration.AddBinding(navigationProperty, targetEntitySet);
             }
         }
     }
 }
Пример #5
0
        private static void AddNavigationBindings(NavigationSourceConfiguration configuration,
            EdmNavigationSource navigationSource,
            NavigationSourceLinkBuilderAnnotation linkBuilder,
            ODataModelBuilder builder,
            Dictionary<Type, IEdmType> edmTypeMap,
            Dictionary<string, EdmNavigationSource> edmNavigationSourceMap)
        {
            foreach (EntityTypeConfiguration entityType in builder.ThisAndBaseAndDerivedTypes(configuration.EntityType))
            {
                foreach (NavigationPropertyConfiguration navigationProperty in entityType.NavigationProperties)
                {
                    NavigationPropertyBindingConfiguration binding = configuration.FindBinding(navigationProperty);
                    bool isContained = navigationProperty.ContainsTarget;
                    if (binding != null || isContained)
                    {
                        EdmEntityType edmEntityType = edmTypeMap[entityType.ClrType] as EdmEntityType;
                        IEdmNavigationProperty edmNavigationProperty = edmEntityType.NavigationProperties()
                            .Single(np => np.Name == navigationProperty.Name);

                        if (!isContained)
                        {
                            navigationSource.AddNavigationTarget(
                                edmNavigationProperty,
                                edmNavigationSourceMap[binding.TargetNavigationSource.Name]);
                        }

                        NavigationLinkBuilder linkBuilderFunc = configuration.GetNavigationPropertyLink(navigationProperty);
                        if (linkBuilderFunc != null)
                        {
                            linkBuilder.AddNavigationPropertyLinkBuilder(edmNavigationProperty, linkBuilderFunc);
                        }
                    }
                }
            }
        }
        private static void AddNavigationBindings(EntitySetConfiguration configuration, EdmEntitySet entitySet, EntitySetLinkBuilderAnnotation linkBuilder, ODataModelBuilder builder,
            Dictionary<Type, IEdmStructuredType> edmTypeMap, Dictionary<string, EdmEntitySet> edmEntitySetMap)
        {
            foreach (EntityTypeConfiguration entity in builder.ThisAndBaseAndDerivedTypes(configuration.EntityType))
            {
                foreach (NavigationPropertyConfiguration navigation in entity.NavigationProperties)
                {
                    NavigationPropertyBinding binding = configuration.FindBinding(navigation);
                    if (binding != null)
                    {
                        EdmEntityType edmEntityType = edmTypeMap[entity.ClrType] as EdmEntityType;
                        IEdmNavigationProperty edmNavigationProperty = edmEntityType.NavigationProperties().Single(np => np.Name == navigation.Name);

                        entitySet.AddNavigationTarget(edmNavigationProperty, edmEntitySetMap[binding.EntitySet.Name]);

                        Func<EntityInstanceContext, IEdmNavigationProperty, Uri> linkBuilderFunc = configuration.GetNavigationPropertyLink(navigation);
                        if (linkBuilderFunc != null)
                        {
                            linkBuilder.AddNavigationPropertyLinkBuilder(edmNavigationProperty, linkBuilderFunc);
                        }
                    }
                }
            }
        }