public void AddEntitySetMapping_should_add_mapping() { var databaseMapping = new DbDatabaseMapping() .Initialize(new EdmModel().Initialize(), new DbDatabaseMetadata()); var entitySet = new EdmEntitySet(); var entitySetMapping = databaseMapping.AddEntitySetMapping(entitySet); Assert.NotNull(entitySetMapping); Assert.Equal(1, databaseMapping.EntityContainerMappings.Single().EntitySetMappings.Count()); Assert.Same(entitySet, entitySetMapping.EntitySet); }
public void Generate(EdmEntityType entityType, DbDatabaseMapping databaseMapping) { //Contract.Requires(entityType != null); //Contract.Requires(databaseMapping != null); var entitySet = databaseMapping.Model.GetEntitySet(entityType); var entitySetMapping = databaseMapping.GetEntitySetMapping(entitySet) ?? databaseMapping.AddEntitySetMapping(entitySet); var table = entitySetMapping.EntityTypeMappings.Any() ? entitySetMapping.EntityTypeMappings.First().TypeMappingFragments.First().Table : databaseMapping.Database.AddTable(entityType.GetRootType().Name); var entityTypeMappingFragment = new DbEntityTypeMappingFragment { Table = table }; var entityTypeMapping = new DbEntityTypeMapping { EntityType = entityType, IsHierarchyMapping = false }; entityTypeMapping.TypeMappingFragments.Add(entityTypeMappingFragment); entityTypeMapping.SetClrType(entityType.GetClrType()); entitySetMapping.EntityTypeMappings.Add(entityTypeMapping); new PropertyMappingGenerator(_providerManifest) .Generate( entityType, entityType.Properties, entitySetMapping, entityTypeMappingFragment, new List<EdmProperty>(), false); }
public void GetComplexPropertyMappings_should_return_all_complex_property_mappings_for_type() { var databaseMapping = new DbDatabaseMapping() .Initialize(new EdmModel().Initialize(), new DbDatabaseMetadata()); var entitySet = new EdmEntitySet(); var entitySetMapping = databaseMapping.AddEntitySetMapping(entitySet); var entityTypeMapping = new DbEntityTypeMapping(); entitySetMapping.EntityTypeMappings.Add(entityTypeMapping); var entityTypeMappingFragment = new DbEntityTypeMappingFragment(); entityTypeMapping.TypeMappingFragments.Add(entityTypeMappingFragment); var propertyMapping1 = new DbEdmPropertyMapping(); var complexType = new EdmComplexType(); complexType.SetClrType(typeof(object)); propertyMapping1.PropertyPath.Add(new EdmProperty { PropertyType = new EdmTypeReference { EdmType = complexType } }); entityTypeMappingFragment.PropertyMappings.Add(propertyMapping1); var propertyMapping2 = new DbEdmPropertyMapping(); propertyMapping2.PropertyPath.Add(new EdmProperty { PropertyType = new EdmTypeReference() }); propertyMapping2.PropertyPath.Add(new EdmProperty { PropertyType = new EdmTypeReference { EdmType = complexType } }); entityTypeMappingFragment.PropertyMappings.Add(propertyMapping2); Assert.Equal(2, databaseMapping.GetComplexPropertyMappings(typeof(object)).Count()); }
public void GetEntityTypeMapping_should_return_mapping_for_type_by_clrType() { var databaseMapping = new DbDatabaseMapping() .Initialize(new EdmModel().Initialize(), new DbDatabaseMetadata()); var entityType = new EdmEntityType { Name = "Foo" }; entityType.SetClrType(typeof(object)); var entityTypeMapping = new DbEntityTypeMapping { EntityType = entityType }; entityTypeMapping.SetClrType(typeof(object)); databaseMapping.AddEntitySetMapping(new EdmEntitySet()).EntityTypeMappings.Add(entityTypeMapping); Assert.Same(entityTypeMapping, databaseMapping.GetEntityTypeMapping(typeof(object))); }
public void GetEntityTypeMapping_should_return_mapping_for_type() { var databaseMapping = new DbDatabaseMapping() .Initialize(new EdmModel().Initialize(), new DbDatabaseMetadata()); var entityType = new EdmEntityType(); var entityTypeMapping = new DbEntityTypeMapping { EntityType = entityType }; databaseMapping.AddEntitySetMapping(new EdmEntitySet()).EntityTypeMappings.Add(entityTypeMapping); Assert.Same(entityTypeMapping, databaseMapping.GetEntityTypeMapping(entityType)); }
public void Can_get_and_set_mapping_for_entity_set() { var databaseMapping = new DbDatabaseMapping() .Initialize(new EdmModel().Initialize(), new DbDatabaseMetadata()); var entitySet = new EdmEntitySet(); Assert.Same(databaseMapping.AddEntitySetMapping(entitySet), databaseMapping.GetEntitySetMapping(entitySet)); }