public static IEdmModel GetConventionModel()
        {
            ODataConventionModelBuilder        builder   = new ODataConventionModelBuilder();
            EntitySetConfiguration <Employee>  employees = builder.EntitySet <Employee>("Employees");
            EntityTypeConfiguration <Employee> employee  = employees.EntityType;

            employee.EnumProperty <Gender>(e => e.Sex).Name = "Gender";

            employee.Collection.Function("GetEarliestTwoEmployees").ReturnsCollectionFromEntitySet <Employee>("Employees");

            var functionConfiguration = builder.Function("GetAddress");

            functionConfiguration.Parameter <int>("id");
            functionConfiguration.Returns <Address>();

            var actionConfiguration = builder.Action("SetAddress");

            actionConfiguration.Parameter <int>("id");
            actionConfiguration.Parameter <Address>("address");
            actionConfiguration.ReturnsFromEntitySet(employees);

            var resetDataSource = builder.Action("ResetDataSource");

            builder.Namespace = typeof(Employee).Namespace;
            builder.EnableLowerCamelCase();
            var edmModel = builder.GetEdmModel();

            return(edmModel);
        }
Example #2
0
        public void LowerCamelCaser_ProcessReflectedAndDataMemberAttributePropertyNames()
        {
            // Arrange
            var builder = ODataConventionModelBuilderFactory.Create().EnableLowerCamelCase(
                NameResolverOptions.ProcessReflectedPropertyNames | NameResolverOptions.ProcessDataMemberAttributePropertyNames);
            EntityTypeConfiguration <LowerCamelCaserEntity> entityTypeConfiguration = builder.EntitySet <LowerCamelCaserEntity>("Entities").EntityType;

            entityTypeConfiguration.Property(b => b.ID).Name        = "iD";
            entityTypeConfiguration.Property(d => d.Name).Name      = "Name";
            entityTypeConfiguration.EnumProperty(d => d.Color).Name = "Something";
            ComplexTypeConfiguration <LowerCamelCaserComplex> complexTypeConfiguration = builder.ComplexType <LowerCamelCaserComplex>();

            complexTypeConfiguration.CollectionProperty(c => c.Notes).Name = "MyNotes";

            // Act
            IEdmModel model = builder.GetEdmModel();

            // Assert
            IEdmEntityType lowerCamelCaserEntity =
                Assert.Single(model.SchemaElements.OfType <IEdmEntityType>().Where(e => e.Name == "LowerCamelCaserEntity"));
            IEdmComplexType lowerCamelCaserComplex =
                Assert.Single(model.SchemaElements.OfType <IEdmComplexType>().Where(e => e.Name == "LowerCamelCaserComplex"));

            Assert.Equal(5, lowerCamelCaserEntity.Properties().Count());
            Assert.Single(lowerCamelCaserEntity.Properties().Where(p => p.Name == "iD"));
            Assert.Single(lowerCamelCaserEntity.Properties().Where(p => p.Name == "Name"));
            Assert.Single(lowerCamelCaserEntity.Properties().Where(p => p.Name == "details"));
            Assert.Single(lowerCamelCaserEntity.Properties().Where(p => p.Name == "Something"));
            Assert.Single(lowerCamelCaserEntity.Properties().Where(p => p.Name == "complexProperty"));
            Assert.Equal(2, lowerCamelCaserComplex.Properties().Count());
            Assert.Single(lowerCamelCaserComplex.Properties().Where(p => p.Name == "price"));
            Assert.Single(lowerCamelCaserComplex.Properties().Where(p => p.Name == "MyNotes"));
        }
Example #3
0
        public static IEdmModel GetModel()
        {
            ODataConventionModelBuilder        builder   = new ODataConventionModelBuilder();
            EntitySetConfiguration <Employee>  employees = builder.EntitySet <Employee>("Employees");
            EntityTypeConfiguration <Employee> employee  = employees.EntityType;

            employee.EnumProperty <Gender>(e => e.Sex).Name = "Gender";

            var resetDataSource = builder.Action("ResetDataSource");

            builder.Namespace = typeof(Employee).Namespace;

            // All the property names in the generated Edm Model will become camel case if EnableLowerCamelCase() is called.
            builder.EnableLowerCamelCase();
            var edmModel = builder.GetEdmModel();

            return(edmModel);
        }