public void Apply_should_move_declared_keys_head_of_declared_properties_list() { var entityType = new EdmEntityType(); entityType.SetClrType(typeof(SimpleEntity)); entityType.AddPrimitiveProperty("StaticProperty"); entityType.AddPrimitiveProperty("PrivateProperty"); entityType.AddPrimitiveProperty("InheritedPropertyB"); entityType.AddPrimitiveProperty("InheritedPropertyA"); entityType.AddPrimitiveProperty("PropertyB"); entityType.AddPrimitiveProperty("PropertyA"); entityType.DeclaredKeyProperties.Add( entityType.AddPrimitiveProperty("Key")); ((IEdmConvention<EdmEntityType>)new DeclaredPropertyOrderingConvention()) .Apply(entityType, new EdmModel()); Assert.True( entityType.DeclaredProperties.Select(e => e.Name) .SequenceEqual( new[] { "Key", "PrivateProperty", "PropertyA", "PropertyB", "InheritedPropertyA", "InheritedPropertyB", "StaticProperty" })); }
public void Can_get_and_set_clr_type_annotation() { var entityType = new EdmEntityType(); Assert.Null(entityType.GetClrType()); entityType.SetClrType(typeof(object)); Assert.Equal(typeof(object), entityType.GetClrType()); }
public TestModelBuilder Entity(string name, bool addSet = true) { _entityType = _model.AddEntityType(name); _entityType.SetClrType(new MockType(name)); if (addSet) { _model.AddEntitySet(name + "Set", _entityType); } return this; }
public void Generate_should_add_set_mapping_and_table_and_set_clr_type() { var databaseMapping = CreateEmptyModel(); var entityType = new EdmEntityType { Name = "E" }; var entitySet = databaseMapping.Model.AddEntitySet("ESet", entityType); entityType.SetClrType(typeof(object)); new EntityTypeMappingGenerator(ProviderRegistry.Sql2008_ProviderManifest).Generate(entityType, databaseMapping); Assert.NotNull(databaseMapping.GetEntitySetMapping(entitySet)); Assert.Same(entityType, databaseMapping.GetEntitySetMapping(entitySet).EntityTypeMappings.Single().EntityType); Assert.Same(typeof(object), databaseMapping.GetEntitySetMapping(entitySet).EntityTypeMappings.Single().GetClrType()); Assert.NotNull(databaseMapping.GetEntitySetMapping(entitySet).EntityTypeMappings.Single().TypeMappingFragments.Single().Table); }
public void Generate_should_map_scalar_properties_to_columns() { var databaseMapping = CreateEmptyModel(); var entityType = new EdmEntityType { Name = "E" }; entityType.AddPrimitiveProperty("P1").PropertyType.EdmType = EdmPrimitiveType.Int32; entityType.AddPrimitiveProperty("P2").PropertyType.EdmType = EdmPrimitiveType.String; var entitySet = databaseMapping.Model.AddEntitySet("ESet", entityType); entityType.SetClrType(typeof(object)); new EntityTypeMappingGenerator(ProviderRegistry.Sql2008_ProviderManifest).Generate(entityType, databaseMapping); var entityTypeMappingFragment = databaseMapping.GetEntitySetMapping(entitySet).EntityTypeMappings.Single().TypeMappingFragments.Single(); Assert.Equal(2, entityTypeMappingFragment.PropertyMappings.Count()); Assert.Equal(2, entityTypeMappingFragment.Table.Columns.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))); }