public void Configure_should_throw_when_property_not_found() { var complexType = new EdmComplexType { Name = "C" }; var complexTypeConfiguration = new ComplexTypeConfiguration(typeof(object)); var mockPropertyConfiguration = new Mock<PrimitivePropertyConfiguration>(); complexTypeConfiguration.Property(new PropertyPath(new MockPropertyInfo()), () => mockPropertyConfiguration.Object); Assert.Equal(Strings.PropertyNotFound(("P"), "C"), Assert.Throws<InvalidOperationException>(() => complexTypeConfiguration.Configure(complexType)).Message); }
public void Add_complex_type_configuration_should_add_to_model_configuration() { var modelConfiguration = new ModelConfiguration(); var complexTypeConfiguration = new ComplexTypeConfiguration<object>(); new ConfigurationRegistrar(modelConfiguration).Add(complexTypeConfiguration); Assert.Same(complexTypeConfiguration.Configuration, modelConfiguration.ComplexType(typeof(object))); }
public void Configure_should_set_configuration() { var complexType = new EdmComplexType { Name = "C" }; var complexTypeConfiguration = new ComplexTypeConfiguration(typeof(object)); complexTypeConfiguration.Configure(complexType); Assert.Same(complexTypeConfiguration, complexType.GetConfiguration()); }
public void TimestampConvention_DoesntApplyWhenTheAttributeIsAppliedOnANonEntityType() { // Arrange PropertyInfo property = CreateMockPropertyInfo("TestProperty"); ComplexTypeConfiguration complexType = new ComplexTypeConfiguration(); PrimitivePropertyConfiguration primitiveProperty = new PrimitivePropertyConfiguration(property, complexType); complexType.ExplicitProperties.Add(property, primitiveProperty); TimestampAttributeEdmPropertyConvention convention = new TimestampAttributeEdmPropertyConvention(); // Act convention.Apply(primitiveProperty, complexType); // Assert Assert.False(primitiveProperty.ConcurrencyToken); }
public void Configure_should_configure_properties() { var complexType = new EdmComplexType { Name = "C" }; var property = complexType.AddPrimitiveProperty("P"); property.PropertyType.EdmType = EdmPrimitiveType.Int32; var complexTypeConfiguration = new ComplexTypeConfiguration(typeof(object)); var mockPropertyConfiguration = new Mock<PrimitivePropertyConfiguration>(); var mockPropertyInfo = new MockPropertyInfo(); complexTypeConfiguration.Property(new PropertyPath(mockPropertyInfo), () => mockPropertyConfiguration.Object); property.SetClrPropertyInfo(mockPropertyInfo); complexTypeConfiguration.Configure(complexType); mockPropertyConfiguration.Verify(p => p.Configure(property)); }
public void Configure_IsConcurrencyToken_using_configuration() { var modelBuilder = new AdventureWorksModelBuilder(); var configuration = new ComplexTypeConfiguration<UnitMeasure>(); configuration.Property(u => u.UnitMeasureCode).IsConcurrencyToken(); modelBuilder.Configurations.Add(configuration); modelBuilder.Entity<BillOfMaterials>().Ignore(b => b.Product); modelBuilder.Entity<BillOfMaterials>().Ignore(b => b.Product1); var databaseMapping = BuildMapping(modelBuilder); databaseMapping.AssertValid(); Assert.Equal( ConcurrencyMode.Fixed, databaseMapping.Model.Namespaces.Single().ComplexTypes.Single() .Properties.Single(p => p.Name == "UnitMeasureCode").ConcurrencyMode); }
public void Configure_is_max_length_on_complex_property_using_configuration() { Configure_is_max_length_on_complex_property( modelBuilder => { var configuration = new ComplexTypeConfiguration<UnitMeasure>(); configuration.Property(u => u.Name).IsMaxLength(); modelBuilder.Configurations.Add(configuration); modelBuilder.Entity<BillOfMaterials>().Ignore(b => b.Product); modelBuilder.Entity<BillOfMaterials>().Ignore( b => b.Product1); }); }
private static IEdmModel GetExplicitModel() { ODataModelBuilder builder = new ODataModelBuilder(); EntitySetConfiguration <ModelAliasingMetadataCustomer> customers = builder.EntitySet <ModelAliasingMetadataCustomer>("Customers"); customers.EntityType.HasKey(c => c.Id); customers.EntityType.Property(c => c.Name); customers.EntityType.ComplexProperty(c => c.BillingAddress); customers.EntityType.ComplexProperty(c => c.DefaultShippingAddress); customers.EntityType.HasMany(c => c.Orders); EntityTypeConfiguration <ModelAliasingMetadataExpressOrder> expressOrder = builder.EntityType <ModelAliasingMetadataExpressOrder>().DerivesFrom <ModelAliasingMetadataOrder>(); expressOrder.Property(eo => eo.ExpressFee); expressOrder.Property(eo => eo.GuaranteedDeliveryDate); EntityTypeConfiguration <ModelAliasingMetadataFreeDeliveryOrder> freeDeliveryOrder = builder.EntityType <ModelAliasingMetadataFreeDeliveryOrder>().DerivesFrom <ModelAliasingMetadataOrder>(); freeDeliveryOrder.Property(fdo => fdo.EstimatedDeliveryDate); EntitySetConfiguration <ModelAliasingMetadataOrder> orders = builder.EntitySet <ModelAliasingMetadataOrder>("Orders"); orders.EntityType.HasKey(o => o.Id); orders.EntityType.Property(o => o.PurchaseDate); orders.EntityType.ComplexProperty(o => o.ShippingAddress); orders.EntityType.HasMany(o => o.Details); EntitySetConfiguration <ModelAliasingMetadataOrderLine> ordersLines = builder.EntitySet <ModelAliasingMetadataOrderLine>("OrdersLines"); ordersLines.EntityType.HasKey(ol => ol.Id); ordersLines.EntityType.HasOptional(ol => ol.Item); ordersLines.EntityType.Property(ol => ol.Price); ordersLines.EntityType.Property(ol => ol.Ammount); ComplexTypeConfiguration <ModelAliasingMetadataAddress> address = builder.ComplexType <ModelAliasingMetadataAddress>(); address.Property(a => a.FirstLine); address.Property(a => a.SecondLine); address.Property(a => a.ZipCode); address.Property(a => a.City); address.ComplexProperty(a => a.Country); ComplexTypeConfiguration <ModelAliasingMetadataRegion> region = builder.ComplexType <ModelAliasingMetadataRegion>(); region.Property(r => r.Country); region.Property(r => r.State); EntitySetConfiguration <ModelAliasingMetadataProduct> products = builder.EntitySet <ModelAliasingMetadataProduct>("Products"); products.EntityType.HasKey(p => p.Id); products.EntityType.Property(p => p.Name); products.EntityType.CollectionProperty(p => p.Regions); customers.EntityType.Name = "Customer"; customers.EntityType.Namespace = "ModelAliasing"; customers.EntityType.ComplexProperty(c => c.BillingAddress).Name = "FinancialAddress"; customers.EntityType.Property(c => c.Name).Name = "ClientName"; customers.EntityType.HasMany(c => c.Orders).Name = "Purchases"; orders.EntityType.Name = "Order"; orders.EntityType.Namespace = "AliasedNamespace"; expressOrder.Name = "ExpressOrder"; expressOrder.Namespace = "Purchasing"; expressOrder.Property(eo => eo.ExpressFee).Name = "Fee"; freeDeliveryOrder.Name = "FreeOrder"; freeDeliveryOrder.Namespace = "Purchasing"; ordersLines.EntityType.Property(ol => ol.Price).Name = "Cost"; region.Name = "PoliticalRegion"; region.Namespace = "Location"; address.Name = "Direction"; address.Namespace = "Location"; address.ComplexProperty <ModelAliasingMetadataRegion>(c => c.Country).Name = "Reign"; return(builder.GetEdmModel()); }
public void Add <T>(ComplexTypeConfiguration <T> configuration) where T : class { dbModelBuilder.Configurations.Add(configuration); }
private static void MapPrice(ComplexTypeConfiguration <Price> m) { m.Property(p => p.IncVat).HasColumnName("PriceIncVat"); m.Property(p => p.ExVat).HasColumnName("PriceExVat"); }
private void CreateEdmTypeHeader(IEdmTypeConfiguration config) { IEdmType edmType = GetEdmType(config.ClrType); if (edmType == null) { if (config.Kind == EdmTypeKind.Complex) { ComplexTypeConfiguration complex = (ComplexTypeConfiguration)config; IEdmComplexType baseType = null; if (complex.BaseType != null) { CreateEdmTypeHeader(complex.BaseType); baseType = GetEdmType(complex.BaseType.ClrType) as IEdmComplexType; Contract.Assert(baseType != null); } EdmComplexType complexType = new EdmComplexType(config.Namespace, config.Name, baseType, complex.IsAbstract ?? false, complex.IsOpen); _types.Add(config.ClrType, complexType); if (complex.IsOpen) { // add a mapping between the open complex type and its dynamic property dictionary. _openTypes.Add(complexType, complex.DynamicPropertyDictionary); } edmType = complexType; } else if (config.Kind == EdmTypeKind.Entity) { EntityTypeConfiguration entity = config as EntityTypeConfiguration; Contract.Assert(entity != null); IEdmEntityType baseType = null; if (entity.BaseType != null) { CreateEdmTypeHeader(entity.BaseType); baseType = GetEdmType(entity.BaseType.ClrType) as IEdmEntityType; Contract.Assert(baseType != null); } EdmEntityType entityType = new EdmEntityType(config.Namespace, config.Name, baseType, entity.IsAbstract ?? false, entity.IsOpen, entity.HasStream); _types.Add(config.ClrType, entityType); if (entity.IsOpen) { // add a mapping between the open entity type and its dynamic property dictionary. _openTypes.Add(entityType, entity.DynamicPropertyDictionary); } edmType = entityType; } else { EnumTypeConfiguration enumTypeConfiguration = config as EnumTypeConfiguration; // The config has to be enum. Contract.Assert(enumTypeConfiguration != null); _types.Add(enumTypeConfiguration.ClrType, new EdmEnumType(enumTypeConfiguration.Namespace, enumTypeConfiguration.Name, GetTypeKind(enumTypeConfiguration.UnderlyingType), enumTypeConfiguration.IsFlags)); } } IEdmStructuredType structuredType = edmType as IEdmStructuredType; StructuralTypeConfiguration structuralTypeConfiguration = config as StructuralTypeConfiguration; if (structuredType != null && structuralTypeConfiguration != null && !_structuredTypeQuerySettings.ContainsKey(structuredType)) { //ModelBoundQuerySettings querySettings = // structuralTypeConfiguration.QueryConfiguration.ModelBoundQuerySettings; //if (querySettings != null) //{ // _structuredTypeQuerySettings.Add(structuredType, // structuralTypeConfiguration.QueryConfiguration.ModelBoundQuerySettings); //} } }