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")); }
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()); }
private static IEdmModel GetEdmModel() { ODataModelBuilder builder = new ODataModelBuilder(); // Configure LimitedEntity EntitySetConfiguration <LimitedEntity> limitedEntities = builder.EntitySet <LimitedEntity>("LimitedEntities"); limitedEntities.EntityType.HasKey(p => p.Id); limitedEntities.EntityType.ComplexProperty(c => c.ComplexProperty); limitedEntities.EntityType.CollectionProperty(c => c.ComplexCollectionProperty).IsNotCountable(); limitedEntities.EntityType.HasMany(l => l.EntityCollectionProperty).IsNotCountable(); limitedEntities.EntityType.CollectionProperty(cp => cp.Integers).IsNotCountable(); // Configure LimitedRelatedEntity EntitySetConfiguration <LimitedRelatedEntity> limitedRelatedEntities = builder.EntitySet <LimitedRelatedEntity>("LimitedRelatedEntities"); limitedRelatedEntities.EntityType.HasKey(p => p.Id); limitedRelatedEntities.EntityType.CollectionProperty(p => p.ComplexCollectionProperty).IsNotCountable(); // Configure Complextype ComplexTypeConfiguration <LimitedComplex> complexType = builder.ComplexType <LimitedComplex>(); complexType.CollectionProperty(p => p.Strings).IsNotCountable(); complexType.Property(p => p.Value); complexType.CollectionProperty(p => p.SimpleEnums).IsNotCountable(); // Configure EnumType EnumTypeConfiguration <SimpleEnum> enumType = builder.EnumType <SimpleEnum>(); enumType.Member(SimpleEnum.First); enumType.Member(SimpleEnum.Second); enumType.Member(SimpleEnum.Third); enumType.Member(SimpleEnum.Fourth); return(builder.GetEdmModel()); }