Esempio n. 1
0
 private static IEdmModel GetSampleModel()
 {
     ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
     builder.ComplexType<Person>();
     return builder.GetEdmModel();
 }
Esempio n. 2
0
        private static void ConfigOData(HttpConfiguration config)
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            var conventions = ODataRoutingConventions.CreateDefault();
            conventions.Insert(0, new CompositeKeyRoutingConvention());

            builder.ComplexType<Address>();

            builder.EntitySet<Brand>("Brands").EntityType.Collection
                .Action("FormLookups")
                .Returns<Components.BrandFormLookups>();
            builder.EntitySet<Client>("Clients");
            builder.EntitySet<Company>("Companies");
            builder.EntitySet<Condition>("Conditions");
            builder.EntitySet<Job>("Jobs").EntityType.Collection
                .Action("FormLookups")
                .Returns<Components.JobFormLookups>();
            builder.EntitySet<JobRepairReason>("JobRepairReasons");
            builder.EntitySet<JobWorkDone>("JobWorkDone");
            builder.EntitySet<Model>("Models").EntityType.Collection
                .Action("FormLookups")
                .Returns<Components.ModelFormLookups>();
            builder.EntitySet<RepairReason>("RepairReasons");
            builder.EntitySet<User>("Users");
            builder.EntitySet<WorkDone>("WorkDone");

            builder.ComplexType<Components.KeyValueResult<string, string>>();

            var EDM = builder.GetEdmModel();

            // OData v4.0
            //config.MapODataServiceRoute("odata", "odata", EDM,
            //    new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));

            config.Routes.MapODataServiceRoute("odata", "odata", EDM,
                new DefaultODataPathHandler(),
                conventions,
                new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));
        }
        private static HttpServer CreateServer(string customersEntitySet)
        {
            HttpConfiguration configuration = new HttpConfiguration();

            ODataModelBuilder builder = new ODataConventionModelBuilder();

            builder.EntitySet<EnableQueryCustomer>(customersEntitySet);
            builder.Entity<PremiumEnableQueryCustomer>();

            builder.EntitySet<EnableQueryCategory>("EnableQueryCategories");
            builder.Entity<PremiumEnableQueryCategory>();

            builder.EntitySet<EnableQueryOrder>("EnableQueryOrders");
            builder.Entity<DiscountedEnableQueryOrder>();

            builder.EntitySet<EnableQueryOrderLine>("EnableQueryOrderLines");

            builder.ComplexType<EnableQueryAddress>();

            IEdmModel model = builder.GetEdmModel();

            configuration.Routes.MapODataServiceRoute("odata", "odata", model);

            return new HttpServer(configuration);
        }
Esempio n. 4
0
        private static IEdmModel GetEdmModel()
        {
            ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
            modelBuilder.ContainerName = "WebApiCtx";

            //modelBuilder.EntitySet<TestDataObj>("Values");
            var holidays = modelBuilder.EntitySet<Model.WorkCalendar>("Holidays");
            holidays.EntityType.Property(h => h.Comment).IsOptional();
            holidays.EntityType.Ignore(h => h.DayType);
            holidays.EntityType.Ignore(h => h.BankDate);
            holidays.EntityType.Ignore(h => h.BankDate_Key);

            //var companies = modelBuilder.EntitySet<Model.Company>("Companies");
            var govs = modelBuilder.EntitySet<Model.Governor>("Governors");
            govs.HasEditLink(
                entityContext => entityContext.Url.ODataLink(
                    new EntitySetPathSegment(entityContext.EntitySet.Name),
                    new KeyValuePathSegment(ODataUriUtils.ConvertToUriLiteral(entityContext.EntityInstance.Id, ODataVersion.V3))),
                followsConventions: true);

            var c = modelBuilder.ComplexType<Model.Company>();
            c.Property(o => o.lawFormValue);
            c.Ignore(o => o.FullName);
            c.Ignore(o => o.LawForm);

            govs.EntityType.ComplexProperty(g => g.Company).IsRequired();

            var assets = modelBuilder.EntitySet<Model.AssetValue>("Assets");
            assets.HasEditLink(
                entityContext => entityContext.Url.ODataLink(
                    new EntitySetPathSegment(entityContext.EntitySet.Name),
                    new KeyValuePathSegment(ODataUriUtils.ConvertToUriLiteral(entityContext.EntityInstance.Id, ODataVersion.V3))),
                followsConventions: true);

            assets.HasRequiredBinding(a => a.Governor, govs);
            assets.EntityType.Property(a => a.InsuranceTypeValue).IsRequired();
            //assets.EntityType.ComplexProperty(a => a.Governor);
            assets.EntityType.Ignore(a => a.InsuranceType);
            assets.EntityType.Ignore(a => a.InsuranceTypeString);

            assets.HasNavigationPropertiesLink(
                assets.EntityType.NavigationProperties,
                (entityContext, navigationProperty) =>
                    new Uri(entityContext.Url.ODataLink(
                        new EntitySetPathSegment(entityContext.EntitySet.Name),
                        new KeyValuePathSegment(ODataUriUtils.ConvertToUriLiteral(entityContext.EntityInstance.Id, ODataVersion.V3)),
                        new NavigationPathSegment(navigationProperty.Name))),
                followsConventions: true);

            govs.HasNavigationPropertiesLink(
                govs.EntityType.NavigationProperties,
                (entityContext, navigationProperty) =>
                    new Uri(entityContext.Url.ODataLink(
                        new EntitySetPathSegment(entityContext.EntitySet.Name),
                        new KeyValuePathSegment(ODataUriUtils.ConvertToUriLiteral(entityContext.EntityInstance.Id, ODataVersion.V3)),
                        new NavigationPathSegment(navigationProperty.Name))),
                followsConventions: true);

            var actionRep = assets.EntityType.Collection.Action("Report");
            actionRep.Parameter<DateTime>("DateBegin");
            actionRep.Parameter<DateTime>("DateEnd");
            actionRep.Parameter<byte>("InsuranceType");
            actionRep.Parameter<Guid?>("GovernorId");
            actionRep.Returns<string>();

            var actionBatch = assets.EntityType.Collection.Action("CreateBatch");
            actionBatch.CollectionParameter<string>("Values");
            actionBatch.Returns<bool>();

            IEdmModel model = modelBuilder.GetEdmModel();
            return model;
        }