public void Apply(EntitySetConfiguration configuration, ODataModelBuilder model)
        {
            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            // generate links without cast for declared and inherited navigation properties
            foreach (EntityTypeConfiguration entity in configuration.EntityType.ThisAndBaseTypes())
            {
                foreach (NavigationPropertyConfiguration property in entity.NavigationProperties)
                {
                    if (configuration.GetNavigationPropertyLink(property) == null)
                    {
                        configuration.HasNavigationPropertyLink(
                                property,
                                (entityContext, navigationProperty) => GenerateNavigationPropertyLink(entityContext, navigationProperty, configuration, includeCast: false));
                    }
                }
            }

            // generate links with cast for navigation properties in derived types.
            foreach (EntityTypeConfiguration entity in model.DerivedTypes(configuration.EntityType))
            {
                foreach (NavigationPropertyConfiguration property in entity.NavigationProperties)
                {
                    if (configuration.GetNavigationPropertyLink(property) == null)
                    {
                        configuration.HasNavigationPropertyLink(
                                property,
                                (entityContext, navigationProperty) => GenerateNavigationPropertyLink(entityContext, navigationProperty, configuration, includeCast: true));
                    }
                }
            }
        }
        internal static Uri GenerateSelfLink(EntitySetConfiguration configuration, EntityInstanceContext entityContext, bool includeCast)
        {
            string routeName;

            Dictionary<string, object> routeValues = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
            routeValues.Add(LinkGenerationConstants.Controller, configuration.Name);
            routeValues.Add(LinkGenerationConstants.Id, ConventionsHelpers.GetEntityKeyValue(entityContext, configuration.EntityType));

            if (includeCast)
            {
                routeName = ODataRouteNames.GetByIdWithCast;
                routeValues.Add(LinkGenerationConstants.Entitytype, entityContext.EntityType.FullName());
            }
            else
            {
                routeName = ODataRouteNames.GetById;
            }

            string editLink = entityContext.UrlHelper.Link(routeName, routeValues);
            if (editLink == null)
            {
                throw Error.InvalidOperation(SRResources.GetByIdRouteMissingOrIncorrect, routeName);
            }

            return new Uri(editLink);
        }
Ejemplo n.º 3
0
        private static IEdmModel GetModel()
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder();

            EntitySetConfiguration <Customer> customers = builder.EntitySet <Customer>("Customers");

            customers.EntityType.ComplexProperty(c => c.Address).IsFilterable().IsSortable();
            builder.EntitySet <Order>("Orders");

            return(builder.GetEdmModel());
        }
Ejemplo n.º 4
0
        private static IEdmModel GetModel()
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder();
            EntitySetConfiguration <Customer>            customers    = builder.EntitySet <Customer>("Customers");
            EntityTypeConfiguration <VipCustomer>        vipCustoemer = builder.Entity <VipCustomer>().DerivesFrom <Customer>();
            EntitySetConfiguration <Order>               orders       = builder.EntitySet <Order>("Orders");
            EntitySetConfiguration <Address>             address      = builder.EntitySet <Address>("Addresses");
            EntitySetConfiguration <PersonalInformation> information  = builder.EntitySet <PersonalInformation>("Informations");

            return(builder.GetEdmModel());
        }
        public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes(); //This has to be called before the following OData mapping, so also before WebApi mapping

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            EntitySetConfiguration <AuthorizedUser> authorizedUsers = builder.EntitySet <AuthorizedUser>("AuthorizedUser");

            config.MapODataServiceRoute("ODataRoute", "odata", builder.GetEdmModel());
            config.AddODataQueryFilter();
        }
    private static IEdmModel GetModel()
    {
        ODataModelBuilder builder = new ODataConventionModelBuilder();
        EntitySetConfiguration <Product> product = builder.EntitySet <Product>("Products");

        product.EntityType.Name      = "Product";
        product.EntityType.Namespace = "TestAPI.Models";
        product.EntityType.Property(p => p.Name).Name  = "DisplayName";
        product.EntityType.Property(p => p.Level).Name = "DisplayLevel";
        return(builder.GetEdmModel());
    }
        private static IEdmModel GetEdmModel()
        {
            ODataConventionModelBuilder             builder                = new ODataConventionModelBuilder();
            EntitySetConfiguration <ETagsCustomer>  eTagsCustomersSet      = builder.EntitySet <ETagsCustomer>("ETagsCustomers");
            EntityTypeConfiguration <ETagsCustomer> eTagsCustomers         = eTagsCustomersSet.EntityType;
            SingletonConfiguration <ETagsCustomer>  eTagsCustomerSingleton = builder.Singleton <ETagsCustomer>("ETagsCustomer");

            eTagsCustomers.Property(c => c.Id).IsConcurrencyToken();
            eTagsCustomers.Property(c => c.Name).IsConcurrencyToken();
            return(builder.GetEdmModel());
        }
        private static IEdmModel GetModel(WebRouteConfiguration configuration)
        {
            ODataModelBuilder builder = configuration.CreateConventionModelBuilder();
            EntitySetConfiguration <UnqualifiedCar> cars = builder.EntitySet <UnqualifiedCar>("UnqualifiedCars");

            cars.EntityType.Action("Wash").Returns <string>();
            cars.EntityType.Collection.Action("Wash").Returns <string>();
            cars.EntityType.Function("Check").Returns <string>();
            cars.EntityType.Collection.Function("Check").Returns <string>();
            return(builder.GetEdmModel());
        }
Ejemplo n.º 9
0
        private static IEdmModel GetModel(WebRouteConfiguration config)
        {
            ODataModelBuilder builder = config.CreateConventionModelBuilder();
            EntitySetConfiguration <ActionProduct> products = builder.EntitySet <ActionProduct>("Products");
            ActionConfiguration productsByCategory          = products.EntityType.Action("GetProductsByCategory");
            ActionConfiguration getSpecialProduct           = products.EntityType.Action("GetSpecialProduct");

            productsByCategory.ReturnsCollectionFromEntitySet <ActionProduct>(products);
            getSpecialProduct.ReturnsFromEntitySet <ActionProduct>(products);
            return(builder.GetEdmModel());
        }
        protected static IEdmModel GetEdmModel()
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder();
            EntitySetConfiguration <DefaultBatchCustomer> customers = builder.EntitySet <DefaultBatchCustomer>("DefaultBatchCustomer");
            EntitySetConfiguration <DefaultBatchOrder>    orders    = builder.EntitySet <DefaultBatchOrder>("DefaultBatchOrder");

            customers.EntityType.Collection.Action("OddCustomers").ReturnsCollectionFromEntitySet <DefaultBatchCustomer>("DefaultBatchCustomer");
            builder.MaxDataServiceVersion = builder.DataServiceVersion;
            builder.Namespace             = typeof(DefaultBatchCustomer).Namespace;
            return(builder.GetEdmModel());
        }
        public void CtorThatTakesClrType_Sets_Property_Name()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();

            // Act
            EntitySetConfiguration entityset = new EntitySetConfiguration(builder, typeof(EntitySetConfigurationTest), "entityset");

            // Assert
            Assert.Equal("entityset", entityset.Name);
        }
Ejemplo n.º 12
0
        public static IEdmModel GetModel()
        {
            ODataConventionModelBuilder      builder  = new ODataConventionModelBuilder();
            EntitySetConfiguration <Account> accounts = builder.EntitySet <Account>("Accounts");

            builder.Namespace = typeof(Account).Namespace;

            var edmModel = builder.GetEdmModel();

            return(edmModel);
        }
        /// <inheritdoc />
        public override EntitySetConfiguration AddEntitySet(string name, EntityTypeConfiguration entityType)
        {
            EntitySetConfiguration entitySetConfiguration = base.AddEntitySet(name, entityType);

            if (this._isModelBeingBuilt)
            {
                this.ApplyNavigationSourceConventions(entitySetConfiguration);
            }

            return(entitySetConfiguration);
        }
Ejemplo n.º 14
0
        public void CtorThatTakesEntityTypeConfiguration_Sets_Property_EntityType()
        {
            // Arrange
            ODataModelBuilder       builder    = new ODataModelBuilder();
            EntityTypeConfiguration entityType = new EntityTypeConfiguration(new ODataModelBuilder(), typeof(EntitySetConfigurationTest));

            // Act
            EntitySetConfiguration entityset = new EntitySetConfiguration(builder, entityType, "entityset");

            // Assert
            Assert.Equal(entityType, entityset.EntityType);
        }
        private void BuildDto <TDto>(ODataModelBuilder odataModelBuilder, TypeInfo apiController)
            where TDto : class
        {
            TypeInfo dtoType        = typeof(TDto).GetTypeInfo();
            string   controllerName = GetControllerName(apiController);
            EntitySetConfiguration <TDto> entitySet = odataModelBuilder.EntitySet <TDto>(controllerName);

            if (GetBaseType(dtoType) == null)
            {
                entitySet.EntityType.DerivesFromNothing();
            }
        }
        private static IEdmModel GetEdmModel(WebRouteConfiguration configuration)
        {
            ODataConventionModelBuilder builder = configuration.CreateConventionModelBuilder();

            EntitySetConfiguration <DollarFormatCustomer> dollarFormatCustomers =
                builder.EntitySet <DollarFormatCustomer>("DollarFormatCustomers");

            EntitySetConfiguration <DollarFormatOrder> dollarFormatOrders =
                builder.EntitySet <DollarFormatOrder>("DollarFormatOrders");

            return(builder.GetEdmModel());
        }
Ejemplo n.º 17
0
        public static IEdmModel GetModel()
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder();

            builder.EntitySet <Address>("Address");
            builder.EntitySet <AddressType>("AddressType");
            builder.EntitySet <BusinessEntity>("BusinessEntity");
            builder.EntitySet <BusinessEntityAddress>("BusinessEntityAddress");
            builder.EntitySet <BusinessEntityContact>("BusinessEntityContact");
            builder.EntitySet <ContactType>("ContactType");
            builder.EntitySet <CountryRegion>("CountryRegion");
            builder.EntitySet <EmailAddress>("EmailAddress");
            builder.EntitySet <Password>("Password");
            builder.EntitySet <Person>("Person");
            builder.EntitySet <PersonPhone>("PersonPhone");
            builder.EntitySet <PhoneNumberType>("PhoneNumberType");
            builder.EntitySet <StateProvince>("StateProvince");

            EntitySetConfiguration <EntityWithEnum> entitesWithEnum
                = builder.EntitySet <EntityWithEnum>("EntityWithEnum");

            FunctionConfiguration functionEntitesWithEnum
                = entitesWithEnum.EntityType.Collection.Function("PersonSearchPerPhoneType");

            functionEntitesWithEnum.Parameter <PhoneNumberTypeEnum>("PhoneNumberTypeEnum");
            functionEntitesWithEnum.ReturnsCollectionFromEntitySet <EntityWithEnum>("EntityWithEnum");

            EntitySetConfiguration <ContactType> contactType = builder.EntitySet <ContactType>("ContactType");
            var actionY = contactType.EntityType.Action("ChangePersonStatus");

            actionY.Parameter <string>("Level");
            actionY.Returns <bool>();

            var changePersonStatusAction = contactType.EntityType.Collection.Action("ChangePersonStatus");

            changePersonStatusAction.Parameter <string>("Level");
            changePersonStatusAction.Returns <bool>();

            EntitySetConfiguration <Person> persons = builder.EntitySet <Person>("Person");

            FunctionConfiguration myFirstFunction = persons.EntityType.Collection.Function("MyFirstFunction");

            myFirstFunction.ReturnsCollectionFromEntitySet <Person>("Person");

            builder.EntitySet <AnimalType>("AnimalType");
            builder.EntitySet <EventData>("EventData");

            builder.EntitySet <Player>("Player");
            builder.EntityType <PlayerStats>();

            return(builder.GetEdmModel());
        }
Ejemplo n.º 18
0
        private static IEdmModel GetDerivedEdmModel()
        {
            ODataConventionModelBuilder            builder           = new ODataConventionModelBuilder();
            EntitySetConfiguration <ETagsCustomer> eTagsCustomersSet = builder.EntitySet <ETagsCustomer>("ETagsCustomers");

            eTagsCustomersSet.HasRequiredBinding(c => c.RelatedCustomer, eTagsCustomersSet);
            eTagsCustomersSet.HasRequiredBinding(c => c.ContainedCustomer, eTagsCustomersSet);
            EntitySetConfiguration <ETagsDerivedCustomer> eTagsDerivedCustomersSet = builder.EntitySet <ETagsDerivedCustomer>("ETagsDerivedCustomers");

            eTagsDerivedCustomersSet.HasRequiredBinding(c => c.RelatedCustomer, eTagsCustomersSet);
            eTagsDerivedCustomersSet.HasRequiredBinding(c => c.ContainedCustomer, eTagsCustomersSet);
            return(builder.GetEdmModel());
        }
Ejemplo n.º 19
0
        private static IEdmModel GetModel(WebRouteConfiguration config)
        {
            ODataModelBuilder builder = config.CreateConventionModelBuilder();
            EntitySetConfiguration <ActionCar>     cars     = builder.EntitySet <ActionCar>("ActionCars");
            EntitySetConfiguration <ActionFerrari> ferraris = builder.EntitySet <ActionFerrari>("ActionFerraris");

            cars.EntityType.Action("Wash").Returns <string>();
            cars.EntityType.Collection.Action("Wash").Returns <string>();
            ActionConfiguration ferrariWash           = ferraris.EntityType.Action("Wash").Returns <string>();
            ActionConfiguration ferrariCollectionWash = ferraris.EntityType.Collection.Action("Wash").Returns <string>();

            return(builder.GetEdmModel());
        }
Ejemplo n.º 20
0
        // Builds the EDM model for the OData service.
        private static IEdmModel GetEdmModel()
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder();
            EntitySetConfiguration <CustomerDto> customers = builder.EntitySet <CustomerDto>("Customers");

            customers.EntityType.HasKey(entity => entity.Id);

            EntitySetConfiguration <OrderDto> orders = builder.EntitySet <OrderDto>("Orders");

            orders.EntityType.Name = "Order";
            orders.EntityType.Property(p => p.Total).Name = "Check";
            return(builder.GetEdmModel());
        }
        private static IEdmModel CreateModel()
        {
            ODataModelBuilder builder = new ODataModelBuilder();
            EntitySetConfiguration <Entity> entities = builder.EntitySet <Entity>("entities");

            builder.EntitySet <RelatedEntity>("related");
            NavigationPropertyConfiguration entityToRelated =
                entities.EntityType.HasOptional <RelatedEntity>((e) => e.Related);

            entities.HasNavigationPropertyLink(entityToRelated, (a, b) => new Uri("aa:b"), false);

            return(builder.GetEdmModel());
        }
Ejemplo n.º 22
0
        private static IEdmModel GetModel()
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder();

            builder.ModelAliasingEnabled = true;

            EntitySetConfiguration <CustomerDto> customers = builder.EntitySet <CustomerDto>("Customers");
            EntitySetConfiguration <OrderDto>    orders    = builder.EntitySet <OrderDto>("Orders");

            orders.EntityType.Name = "Order";
            orders.EntityType.Property(p => p.Total).Name = "Check";
            return(builder.GetEdmModel());
        }
Ejemplo n.º 23
0
        public void GetTargetEntitySet_Returns_Null_IfNoMatchingTargetEntitySet()
        {
            // Arrange
            ODataModelBuilder               builder            = new ODataModelBuilder();
            EntityTypeConfiguration         motorcycle         = builder.AddEntity(typeof(Motorcycle));
            NavigationPropertyConfiguration navigationProperty = motorcycle.AddNavigationProperty(typeof(Motorcycle).GetProperty("Manufacturer"), EdmMultiplicity.ZeroOrOne);

            // Act
            EntitySetConfiguration targetEntitySet = AssociationSetDiscoveryConvention.GetTargetEntitySet(navigationProperty, builder);

            // Assert
            Assert.Null(targetEntitySet);
        }
        public void Apply(INavigationSourceConfiguration configuration, ODataModelBuilder model)
        {
            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            // Configure the self link for the feed
            EntitySetConfiguration entitySet = configuration as EntitySetConfiguration;

            if (entitySet != null && (entitySet.GetFeedSelfLink() == null))
            {
                entitySet.HasFeedSelfLink(feedContext =>
                {
                    string selfLink = feedContext.Url.CreateODataLink(new EntitySetPathSegment(feedContext.EntitySetBase));

                    if (selfLink == null)
                    {
                        return(null);
                    }
                    return(new Uri(selfLink));
                });
            }

            if (configuration.GetIdLink() == null)
            {
                configuration.HasIdLink(new SelfLinkBuilder <Uri>((entityContext) => entityContext.GenerateSelfLink(includeCast: false), followsConventions: true));
            }

            if (configuration.GetEditLink() == null)
            {
                bool derivedTypesDefineNavigationProperty = model.DerivedTypes(configuration.EntityType)
                                                            .OfType <EntityTypeConfiguration>().Any(e => e.NavigationProperties.Any());

                // generate links with cast if any of the derived types define a navigation property
                if (derivedTypesDefineNavigationProperty)
                {
                    configuration.HasEditLink(
                        new SelfLinkBuilder <Uri>(
                            entityContext => entityContext.GenerateSelfLink(includeCast: true),
                            followsConventions: true));
                }
                else
                {
                    configuration.HasEditLink(
                        new SelfLinkBuilder <Uri>(
                            entityContext => entityContext.GenerateSelfLink(includeCast: false),
                            followsConventions: true));
                }
            }
        }
Ejemplo n.º 25
0
        private IEdmModel GetEdmModel()
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            EntitySetConfiguration <SchoolClasses> schoolClasses = builder.EntitySet <SchoolClasses>("SchoolClasses");

            schoolClasses.EntityType.Count().Filter().OrderBy().Expand().Select();

            EntitySetConfiguration <Pupils> pupils = builder.EntitySet <Pupils>("Pupils");

            pupils.EntityType.Count().Filter().OrderBy().Select();

            return(builder.GetEdmModel());
        }
Ejemplo n.º 26
0
        public static IEdmModel GetExplicitModel(WebRouteConfiguration configuration)
        {
            ODataModelBuilder builder = new ODataModelBuilder();
            var employee = builder.EntityType <Employee>();

            employee.HasKey(c => c.ID);
            employee.Property(c => c.Name);
            employee.CollectionProperty <Skill>(c => c.SkillSet);
            employee.EnumProperty <Gender>(c => c.Gender);
            employee.EnumProperty <AccessLevel>(c => c.AccessLevel);
            employee.ComplexProperty <FavoriteSports>(c => c.FavoriteSports);
            employee.HasInstanceAnnotations(c => c.InstanceAnnotations);

            var skill = builder.EnumType <Skill>();

            skill.Member(Skill.CSharp);
            skill.Member(Skill.Sql);
            skill.Member(Skill.Web);

            var gender = builder.EnumType <Gender>();

            gender.Member(Gender.Female);
            gender.Member(Gender.Male);

            var accessLevel = builder.EnumType <AccessLevel>();

            accessLevel.Member(AccessLevel.Execute);
            accessLevel.Member(AccessLevel.Read);
            accessLevel.Member(AccessLevel.Write);

            var favoriteSports = builder.ComplexType <FavoriteSports>();

            favoriteSports.EnumProperty <Sport>(f => f.LikeMost);
            favoriteSports.CollectionProperty <Sport>(f => f.Like);

            var sport = builder.EnumType <Sport>();

            sport.Member(Sport.Basketball);
            sport.Member(Sport.Pingpong);

            AddBoundActionsAndFunctions(employee);
            AddUnboundActionsAndFunctions(builder);

            EntitySetConfiguration <Employee> employees = builder.EntitySet <Employee>("Employees");

            employees.HasEditLink(link, true);
            employees.HasIdLink(link, true);
            builder.Namespace = "NS";
            return(builder.GetEdmModel());
        }
Ejemplo n.º 27
0
        public static IEdmModel GetExplicitModel()
        {
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration <Window> windowType = builder.EntityType <Window>();

            windowType.HasKey(a => a.Id);
            windowType.Property(a => a.Name).IsRequired();
            windowType.ComplexProperty(w => w.CurrentShape).IsNullable();
            windowType.CollectionProperty(w => w.OptionalShapes);
            windowType.CollectionProperty(w => w.PolygonalShapes);
            windowType.HasOptional <Window>(w => w.Parent);

            ComplexTypeConfiguration <Shape> shapeType = builder.ComplexType <Shape>();

            shapeType.Property(s => s.HasBorder);
            shapeType.Abstract();

            ComplexTypeConfiguration <Circle> circleType = builder.ComplexType <Circle>();

            circleType.ComplexProperty(c => c.Center);
            circleType.Property(c => c.Radius);
            circleType.DerivesFrom <Shape>();

            ComplexTypeConfiguration <Polygon> polygonType = builder.ComplexType <Polygon>();

            polygonType.CollectionProperty(p => p.Vertexes);
            polygonType.DerivesFrom <Shape>();

            ComplexTypeConfiguration <Rectangle> rectangleType = builder.ComplexType <Rectangle>();

            rectangleType.ComplexProperty(r => r.TopLeft);
            rectangleType.Property(r => r.Width);
            rectangleType.Property(r => r.Height);
            rectangleType.DerivesFrom <Polygon>();

            ComplexTypeConfiguration <Point> pointType = builder.ComplexType <Point>();

            pointType.Property(p => p.X);
            pointType.Property(p => p.Y);

            EntitySetConfiguration <Window> windows = builder.EntitySet <Window>("Windows");

            //       windows.HasEditLink(link, true);
            //    windows.HasIdLink(link, true);
            windows.HasOptionalBinding(c => c.Parent, "Windows");

            builder.Namespace = typeof(Window).Namespace;

            return(builder.GetEdmModel());
        }
 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);
             }
         }
     }
 }
        public void Ctor_ThrowsArgumentNull_BindingPath()
        {
            // Assert
            Mock <ODataModelBuilder>          builder          = new Mock <ODataModelBuilder>();
            ComplexTypeConfiguration          complex          = new ComplexTypeConfiguration();
            ComplexTypeConfiguration <object> structuralType   = new ComplexTypeConfiguration <object>(complex);
            EntitySetConfiguration            navigationSource = new EntitySetConfiguration();

            // Act & Assert
            ExceptionAssert.ThrowsArgumentNull(
                () =>
                new BindingPathConfiguration <object>(builder.Object, structuralType, navigationSource,
                                                      bindingPath: null), "bindingPath");
        }
Ejemplo n.º 30
0
        private static IEdmModel GetEdmModel(HttpConfiguration configuration)
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder(configuration);
            EntitySetConfiguration <SingleResultCustomer>         customers       = builder.EntitySet <SingleResultCustomer>("SingleResultCustomers");
            EntitySetConfiguration <SingleResultOrderDetail>      orderDetails    = builder.EntitySet <SingleResultOrderDetail>("SingleResultOrderDetail");
            EntityTypeConfiguration <SingleResultPremiumCustomer> premiumCustomer = builder.Entity <SingleResultPremiumCustomer>();

            customers.EntityType.Action("CreditRating").Returns <double>();
            EntitySetConfiguration <SingleResultOrder> orders  = builder.EntitySet <SingleResultOrder>("SingleResultOrder");
            EntitySetConfiguration <SingleResultBonus> bonuses = builder.EntitySet <SingleResultBonus>("SingleResultBonus");
            IEdmModel model = builder.GetEdmModel();

            return(model);
        }
 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);
             }
         }
     }
 }
Ejemplo n.º 32
0
        public static IEdmModel GetEdmModel(WebRouteConfiguration configuration)
        {
            ODataConventionModelBuilder      builder   = configuration.CreateConventionModelBuilder();
            EntitySetConfiguration <Product> employees = builder.EntitySet <Product>("Products");
            var airPlaneType = builder.EntityType <AirPlane>();

            airPlaneType.DerivesFrom <Product>();

            builder.Namespace = typeof(Product).Namespace;

            var edmModel = builder.GetEdmModel();

            return(edmModel);
        }
Ejemplo n.º 33
0
        private static IEdmModel GetEdmModel(IServiceProvider serviceProvider)
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder(serviceProvider);

            //builder.EntitySet<visitorCarType>("visitorCarType")
            //    .EntityType
            //    .Filter()
            //    .Count()
            //    .Expand()
            //    .OrderBy()
            //    .Page()
            //    .Select();


            builder.EntitySet <vtran>("Vtrans")
            .EntityType
            .Filter()
            .Count()
            .Expand()
            .OrderBy()
            .Page()
            .Select();
            //EntitySetConfiguration<ContactType> contactType = builder.EntitySet<ContactType>("ContactType");
            //var actionY = contactType.EntityType.Action("ChangePersonStatus");
            //actionY.Parameter<string>("Level");
            //actionY.Returns<bool>();

            //var changePersonStatusAction = contactType.EntityType.Collection.Action("ChangePersonStatus");
            //changePersonStatusAction.Parameter<string>("Level");
            //changePersonStatusAction.Returns<bool>();

            //EntitySetConfiguration<visitorCarType> persons = builder.EntitySet<visitorCarType>("visitorCarType");
            //FunctionConfiguration myFirstFunction = persons.EntityType.Collection.Function("MyFirstFunction");
            //myFirstFunction.ReturnsCollectionFromEntitySet<visitorCarType>("visitorCarType");

            EntitySetConfiguration <vtran> vtran = builder.EntitySet <vtran>("vtran");
            FunctionConfiguration          myFirstFunctiontrans = vtran.EntityType.Collection.Function("MyFirstFunctiontrans");

            myFirstFunctiontrans.ReturnsCollectionFromEntitySet <vtran>("vtran");



            //EntitySetConfiguration<EntityWithEnum> entitesWithEnum = builder.EntitySet<EntityWithEnum>("EntityWithEnum");
            //FunctionConfiguration functionEntitesWithEnum = entitesWithEnum.EntityType.Collection.Function("PersonSearchPerPhoneType");
            //functionEntitesWithEnum.Parameter<PhoneNumberTypeEnum>("PhoneNumberTypeEnum");
            //functionEntitesWithEnum.ReturnsCollectionFromEntitySet<EntityWithEnum>("EntityWithEnum");

            return(builder.GetEdmModel());
        }
        public void Apply(EntitySetConfiguration configuration, ODataModelBuilder model)
        {
            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            // Configure the self link for the feed
            if (configuration.GetFeedSelfLink() == null)
            {
                configuration.HasFeedSelfLink(entitySetContext =>
                {
                    string routeName = ODataRouteNames.Default;
                    string selfLink = entitySetContext.UrlHelper.Link(
                        routeName,
                        new
                        {
                            controller = configuration.Name
                        });
                    if (selfLink == null)
                    {
                        throw Error.InvalidOperation(SRResources.DefaultRouteMissingOrIncorrect, routeName);
                    }
                    return new Uri(selfLink);
                });
            }

            // We only need to configure the EditLink by convention, ReadLink and IdLink both delegate to EditLink
            if (configuration.GetEditLink() == null)
            {
                bool derivedTypesDefineNavigationProperty = model.DerivedTypes(configuration.EntityType).Any(e => e.NavigationProperties.Any());

                // generate links with cast if any of the derived types define a navigation property
                if (derivedTypesDefineNavigationProperty)
                {
                    configuration.HasEditLink((entityContext) => GenerateSelfLink(configuration, entityContext, includeCast: true));
                }
                else
                {
                    configuration.HasEditLink((entityContext) => GenerateSelfLink(configuration, entityContext, includeCast: false));
                }
            }
        }
        internal static string GenerateSelfLink(EntitySetConfiguration configuration, EntityInstanceContext entityContext, bool includeCast)
        {
            List<ODataPathSegment> idLinkPathSegments = new List<ODataPathSegment>();

            idLinkPathSegments.Add(new EntitySetPathSegment(entityContext.EntitySet));
            idLinkPathSegments.Add(new KeyValuePathSegment(ConventionsHelpers.GetEntityKeyValue(entityContext, configuration.EntityType)));

            if (includeCast)
            {
                idLinkPathSegments.Add(new CastPathSegment(entityContext.EntityType));
            }

            string idLink = entityContext.Url.ODataLink(idLinkPathSegments);

            if (idLink == null)
            {
                return null;
            }

            return idLink;
        }
        internal static Uri GenerateSelfLink(EntitySetConfiguration configuration, EntityInstanceContext entityContext, bool includeCast)
        {
            List<ODataPathSegment> editLinkPathSegments = new List<ODataPathSegment>();

            editLinkPathSegments.Add(new EntitySetPathSegment(entityContext.EntitySet));
            editLinkPathSegments.Add(new KeyValuePathSegment(ConventionsHelpers.GetEntityKeyValue(entityContext, configuration.EntityType)));

            if (includeCast)
            {
                editLinkPathSegments.Add(new CastPathSegment(entityContext.EntityType));
            }

            string editLink = entityContext.UrlHelper.ODataLink(entityContext.PathHandler, editLinkPathSegments);

            if (editLink == null)
            {
                return null;
            }

            return new Uri(editLink);
        }
        internal static Uri GenerateNavigationPropertyLink(EntityInstanceContext entityContext, IEdmNavigationProperty navigationProperty, EntitySetConfiguration configuration, bool includeCast)
        {
            List<ODataPathSegment> navigationPathSegments = new List<ODataPathSegment>();
            navigationPathSegments.Add(new EntitySetPathSegment(entityContext.EntitySet));
            navigationPathSegments.Add(new KeyValuePathSegment(ConventionsHelpers.GetEntityKeyValue(entityContext, configuration.EntityType)));

            if (includeCast)
            {
                navigationPathSegments.Add(new CastPathSegment(entityContext.EntityType));
            }

            navigationPathSegments.Add(new NavigationPathSegment(navigationProperty));

            string link = entityContext.UrlHelper.ODataLink(entityContext.PathHandler, navigationPathSegments);

            if (link == null)
            {
                return null;
            }

            return new Uri(link);
        }
        public void Apply(EntitySetConfiguration configuration, ODataModelBuilder model)
        {
            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            // Configure the self link for the feed
            if (configuration.GetFeedSelfLink() == null)
            {
                configuration.HasFeedSelfLink(entitySetContext =>
                {
                    string selfLink = entitySetContext.Url.CreateODataLink(new EntitySetPathSegment(entitySetContext.EntitySet));

                    if (selfLink == null)
                    {
                        return null;
                    }
                    return new Uri(selfLink);
                });
            }

            // We only need to configure the IdLink by convention, ReadLink and EditLink both delegate to IdLink
            if (configuration.GetIdLink() == null)
            {
                bool derivedTypesDefineNavigationProperty = model.DerivedTypes(configuration.EntityType).Any(e => e.NavigationProperties.Any());

                // generate links with cast if any of the derived types define a navigation property
                if (derivedTypesDefineNavigationProperty)
                {
                    configuration.HasIdLink(new SelfLinkBuilder<string>((entityContext) => entityContext.GenerateSelfLink(includeCast: true), followsConventions: true));
                }
                else
                {
                    configuration.HasIdLink(new SelfLinkBuilder<string>((entityContext) => entityContext.GenerateSelfLink(includeCast: false), followsConventions: true));
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="NavigationPropertyBindingConfiguration"/> class.
 /// </summary>
 /// <param name="navigationProperty">The navigation property for the binding.</param>
 /// <param name="entitySet">The target entity set of the binding.</param>
 public NavigationPropertyBindingConfiguration(NavigationPropertyConfiguration navigationProperty,
     EntitySetConfiguration entitySet)
 {
     NavigationProperty = navigationProperty;
     EntitySet = entitySet;
 }