public void Apply_should_not_match_composite_key() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddKeyMember(property); entityType.AddKeyMember(EdmProperty.Primitive("K", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String))); ((IEdmConvention <EntityType>) new StoreGeneratedIdentityKeyConvention()) .Apply(entityType, new EdmModel(DataSpace.CSpace)); Assert.Equal( 0, entityType.KeyProperties .Count(p => p.GetStoreGeneratedPattern() == StoreGeneratedPattern.Identity)); }
private IEnumerable <EdmProperty> GenerateIndependentForeignKeyColumns( EntityType principalEntityType, EntityType dependentEntityType, AssociationSetMapping associationSetMapping, EndPropertyMapping associationEndMapping, EntityType dependentTable, bool isPrimaryKeyColumn, NavigationProperty principalNavigationProperty) { foreach (EdmProperty keyProperty in principalEntityType.KeyProperties()) { string columnName = (principalNavigationProperty != null ? principalNavigationProperty.Name : principalEntityType.Name) + "_" + keyProperty.Name; EdmProperty foreignKeyColumn = this.MapTableColumn(keyProperty, columnName, false); dependentTable.AddColumn(foreignKeyColumn); if (isPrimaryKeyColumn) { dependentTable.AddKeyMember((EdmMember)foreignKeyColumn); } foreignKeyColumn.Nullable = associationEndMapping.AssociationEnd.IsOptional() || associationEndMapping.AssociationEnd.IsRequired() && dependentEntityType.BaseType != null; foreignKeyColumn.StoreGeneratedPattern = StoreGeneratedPattern.None; yield return(foreignKeyColumn); associationEndMapping.AddPropertyMapping(new ScalarPropertyMapping(keyProperty, foreignKeyColumn)); if (foreignKeyColumn.Nullable) { associationSetMapping.AddCondition((ConditionPropertyMapping) new IsNullConditionMapping(foreignKeyColumn, false)); } } }
public void Apply_should_not_match_key_that_is_also_an_fk() { var model = new EdmModel(DataSpace.CSpace); var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int64)); entityType.AddKeyMember(property); var associationType = model.AddAssociationType( "A", new EntityType("E", "N", DataSpace.CSpace), RelationshipMultiplicity.ZeroOrOne, entityType, RelationshipMultiplicity.Many); associationType.Constraint = new ReferentialConstraint( associationType.SourceEnd, associationType.TargetEnd, new[] { property }, new[] { property }); ((IEdmConvention <EntityType>) new StoreGeneratedIdentityKeyConvention()) .Apply(entityType, model); Assert.Null(entityType.KeyProperties.Single().GetStoreGeneratedPattern()); }
public void Apply_should_update_foreign_keys() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var principalProperty = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); principalProperty.MaxLength = 23; entityType.AddMember(principalProperty); entityType.AddKeyMember(principalProperty); var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace); associationType.SourceEnd = new AssociationEndMember("S", entityType); associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace)); var dependentProperty = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); associationType.Constraint = new ReferentialConstraint( associationType.SourceEnd, associationType.TargetEnd, new[] { principalProperty }, new[] { dependentProperty }); ((IEdmConvention <AssociationType>) new PropertyMaxLengthConvention()) .Apply(associationType, new EdmModel(DataSpace.CSpace)); Assert.Equal(23, dependentProperty.MaxLength); }
internal override void Configure( AssociationSetMapping associationSetMapping, EdmModel database, PropertyInfo navigationProperty) { List <ScalarPropertyMapping> propertyMappings = associationSetMapping.SourceEndMapping.PropertyMappings.ToList <ScalarPropertyMapping>(); if (this._tableName != null) { EntityType targetTable = database.EntityTypes.Select(t => new { t = t, n = t.GetTableName() }).Where(_param1 => { if (_param1.n != null) { return(_param1.n.Equals(this._tableName)); } return(false); }).Select(_param0 => _param0.t).SingleOrDefault <EntityType>() ?? database.GetEntitySets().Where <EntitySet>((Func <EntitySet, bool>)(es => string.Equals(es.Table, this._tableName.Name, StringComparison.Ordinal))).Select <EntitySet, EntityType>((Func <EntitySet, EntityType>)(es => es.ElementType)).SingleOrDefault <EntityType>(); if (targetTable == null) { throw Error.TableNotFound((object)this._tableName); } EntityType sourceTable = associationSetMapping.Table; if (sourceTable != targetTable) { ForeignKeyBuilder foreignKeyBuilder = sourceTable.ForeignKeyBuilders.Single <ForeignKeyBuilder>((Func <ForeignKeyBuilder, bool>)(fk => fk.DependentColumns.SequenceEqual <EdmProperty>(propertyMappings.Select <ScalarPropertyMapping, EdmProperty>((Func <ScalarPropertyMapping, EdmProperty>)(pm => pm.Column))))); sourceTable.RemoveForeignKey(foreignKeyBuilder); targetTable.AddForeignKey(foreignKeyBuilder); foreignKeyBuilder.DependentColumns.Each <EdmProperty>((Action <EdmProperty>)(c => { bool primaryKeyColumn = c.IsPrimaryKeyColumn; sourceTable.RemoveMember((EdmMember)c); targetTable.AddMember((EdmMember)c); if (!primaryKeyColumn) { return; } targetTable.AddKeyMember((EdmMember)c); })); associationSetMapping.StoreEntitySet = database.GetEntitySet(targetTable); } } if (this._keyColumnNames.Count > 0 && this._keyColumnNames.Count != propertyMappings.Count <ScalarPropertyMapping>()) { throw Error.IncorrectColumnCount((object)string.Join(", ", (IEnumerable <string>) this._keyColumnNames)); } this._keyColumnNames.Each <string>((Action <string, int>)((n, i) => propertyMappings[i].Column.Name = n)); foreach (KeyValuePair <Tuple <string, string>, object> annotation in (IEnumerable <KeyValuePair <Tuple <string, string>, object> >) this._annotations) { int index = this._keyColumnNames.IndexOf(annotation.Key.Item1); if (index == -1) { throw new InvalidOperationException(Strings.BadKeyNameForAnnotation((object)annotation.Key.Item1, (object)annotation.Key.Item2)); } propertyMappings[index].Column.AddAnnotation("http://schemas.microsoft.com/ado/2013/11/edm/customannotation:" + annotation.Key.Item2, annotation.Value); } }
public void Apply_should_set_given_value_for_string_keys() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property); entityType.AddKeyMember(property); (new SqlCePropertyMaxLengthConvention(2000)).Apply(entityType, CreateDbModel()); Assert.Equal(2000, property.MaxLength); }
public void Apply_should_not_match_simple_key_of_wrong_type() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddKeyMember(property); ((IEdmConvention <EntityType>) new StoreGeneratedIdentityKeyConvention()) .Apply(entityType, new EdmModel(DataSpace.CSpace)); Assert.Null(entityType.KeyProperties.Single().GetStoreGeneratedPattern()); }
public void Apply_should_set_correct_defaults_for_string_keys() { var entityType = new EntityType(); var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property); entityType.AddKeyMember(property); ((IEdmConvention <EntityType>) new SqlCePropertyMaxLengthConvention()) .Apply(entityType, CreateEdmModel()); Assert.Equal(4000, property.MaxLength); }
public void Apply_should_set_correct_defaults_for_binary_key() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property); entityType.AddKeyMember(property); (new SqlCePropertyMaxLengthConvention()) .Apply(entityType, CreateDbModel()); Assert.Null(property.IsUnicode); Assert.Equal(4000, property.MaxLength); }
public void Apply_should_set_correct_defaults_for_string_keys() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property); entityType.AddKeyMember(property); ((IEdmConvention <EntityType>) new PropertyMaxLengthConvention()) .Apply(entityType, new EdmModel(DataSpace.CSpace)); Assert.Equal(128, property.MaxLength); }
public TestModelBuilder Key(string key) { var property1 = EdmProperty.Primitive(key, PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); _entityType.AddMember(property1); var property = property1; property.SetClrPropertyInfo(new MockPropertyInfo(typeof(int), key)); _entityType.AddKeyMember(property); return(this); }
public void Apply_should_ignore_when_key_already_specified() { var entityType = new EntityType(); var property1 = EdmProperty.Primitive("Id", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property1); var property = property1; entityType.AddKeyMember(EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String))); ((IEdmConvention <EntityType>) new IdKeyDiscoveryConvention()).Apply(entityType, new EdmModel()); Assert.False(entityType.DeclaredKeyProperties.Contains(property)); }
public void Apply_should_match_simple_short_key() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)); entityType.AddKeyMember(property); (new StoreGeneratedIdentityKeyConvention()) .Apply(entityType, new DbModel(new EdmModel(DataSpace.CSpace), null)); Assert.Equal( StoreGeneratedPattern.Identity, entityType.KeyProperties.Single().GetStoreGeneratedPattern()); }
public void Apply_should_ignore_when_key_already_specified() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property1 = EdmProperty.Primitive("Id", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property1); var property = property1; entityType.AddKeyMember(EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String))); (new IdKeyDiscoveryConvention()).Apply(entityType, new DbModel(new EdmModel(DataSpace.CSpace), null)); Assert.False(entityType.KeyProperties.Contains(property)); }
public void Apply_should_match_simple_short_key() { var entityType = new EntityType(); var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)); entityType.AddKeyMember(property); ((IEdmConvention <EntityType>) new StoreGeneratedIdentityKeyConvention()) .Apply(entityType, new EdmModel().Initialize()); Assert.Equal( StoreGeneratedPattern.Identity, entityType.DeclaredKeyProperties.Single().GetStoreGeneratedPattern()); }
public void Apply_should_set_correct_defaults_for_binary_key() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Binary)); entityType.AddMember(property); entityType.AddKeyMember(property); (new PropertyMaxLengthConvention()) .Apply(entityType, new DbModel(new EdmModel(DataSpace.CSpace), null)); Assert.Null(property.IsUnicode); Assert.Equal(128, property.MaxLength); }
private IEnumerable <EdmProperty> GenerateIndependentForeignKeyColumns( EntityType principalEntityType, EntityType dependentEntityType, StorageAssociationSetMapping associationSetMapping, StorageEndPropertyMapping associationEndMapping, EntityType dependentTable, bool isPrimaryKeyColumn, NavigationProperty principalNavigationProperty) { DebugCheck.NotNull(principalEntityType); DebugCheck.NotNull(associationEndMapping); DebugCheck.NotNull(dependentTable); foreach (var property in principalEntityType.KeyProperties()) { var columnName = ((principalNavigationProperty != null) ? principalNavigationProperty.Name : principalEntityType.Name) + "_" + property.Name; var foreignKeyColumn = MapTableColumn(property, columnName, false); dependentTable.AddColumn(foreignKeyColumn); if (isPrimaryKeyColumn) { dependentTable.AddKeyMember(foreignKeyColumn); } foreignKeyColumn.Nullable = associationEndMapping.EndMember.IsOptional() || (associationEndMapping.EndMember.IsRequired() && dependentEntityType.BaseType != null); foreignKeyColumn.StoreGeneratedPattern = StoreGeneratedPattern.None; yield return(foreignKeyColumn); associationEndMapping.AddProperty(new StorageScalarPropertyMapping(property, foreignKeyColumn)); if (foreignKeyColumn.Nullable) { associationSetMapping .AddColumnCondition(new StorageConditionPropertyMapping(null, foreignKeyColumn, null, false)); } } }
private void ConfigureKey(EntityType entityType) { DebugCheck.NotNull(entityType); if (!_keyProperties.Any()) { return; } if (entityType.BaseType != null) { throw Error.KeyRegisteredOnDerivedType(ClrType, entityType.GetRootType().GetClrType()); } var keyProperties = _keyProperties.AsEnumerable(); if (!_isKeyConfigured) { var primaryKeys = from p in _keyProperties select new { PropertyInfo = p, Property(new PropertyPath(p)).ColumnOrder }; if ((_keyProperties.Count > 1) && primaryKeys.Any(p => !p.ColumnOrder.HasValue)) { throw Error.ModelGeneration_UnableToDetermineKeyOrder(ClrType); } keyProperties = primaryKeys.OrderBy(p => p.ColumnOrder).Select(p => p.PropertyInfo); } foreach (var keyProperty in keyProperties) { var property = entityType.GetDeclaredPrimitiveProperty(keyProperty); if (property == null) { throw Error.KeyPropertyNotFound(keyProperty.Name, entityType.Name); } property.Nullable = false; entityType.AddKeyMember(property); } }
public void Apply_should_move_declared_keys_head_of_declared_properties_list() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var type = typeof(SimpleEntity); entityType.GetMetadataProperties().SetClrType(type); var property1 = EdmProperty.CreatePrimitive("PrivateProperty", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property1); var property2 = EdmProperty.CreatePrimitive("InheritedPropertyB", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property2); var property3 = EdmProperty.CreatePrimitive("InheritedPropertyA", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property3); var property4 = EdmProperty.CreatePrimitive("PropertyB", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property4); var property5 = EdmProperty.CreatePrimitive("PropertyA", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property5); var property6 = EdmProperty.CreatePrimitive("Key", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property6); entityType.AddKeyMember(property6); new DeclaredPropertyOrderingConvention().Apply(entityType, new DbModel(new EdmModel(DataSpace.CSpace), null)); Assert.True( entityType.DeclaredProperties.Select(e => e.Name) .SequenceEqual( new[] { "Key", "PrivateProperty", "PropertyA", "PropertyB", "InheritedPropertyA", "InheritedPropertyB" })); }
public void Apply_should_match_optional_self_ref() { var model = new EdmModel(DataSpace.CSpace); var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int64)); entityType.AddKeyMember(property); model.AddAssociationType( "A", entityType, RelationshipMultiplicity.ZeroOrOne, entityType, RelationshipMultiplicity.Many); (new StoreGeneratedIdentityKeyConvention()) .Apply(entityType, new DbModel(model, null)); Assert.NotNull(entityType.KeyProperties.Single().GetStoreGeneratedPattern()); }
public void Apply_should_match_key_that_is_an_fk_used_in_table_splitting() { var model = new EdmModel(DataSpace.CSpace); var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int64)); entityType.AddKeyMember(property); var targetConfig = new EntityTypeConfiguration(typeof(object)); targetConfig.ToTable("SharedTable"); entityType.Annotations.SetConfiguration(targetConfig); var sourceEntityType = new EntityType("E", "N", DataSpace.CSpace); var sourceConfig = new EntityTypeConfiguration(typeof(object)); sourceConfig.ToTable("SharedTable"); sourceEntityType.Annotations.SetConfiguration(sourceConfig); var associationType = model.AddAssociationType( "A", sourceEntityType, RelationshipMultiplicity.One, entityType, RelationshipMultiplicity.One); associationType.Constraint = new ReferentialConstraint( associationType.SourceEnd, associationType.TargetEnd, new[] { property }, new[] { property }); ((IEdmConvention <EntityType>) new StoreGeneratedIdentityKeyConvention()) .Apply(entityType, model); Assert.Equal( StoreGeneratedPattern.Identity, entityType.KeyProperties.Single().GetStoreGeneratedPattern()); }
public void Apply_should_introduce_constraint_when_one_to_one() { var entityType1 = new EntityType("E", "N", DataSpace.CSpace); entityType1.AddKeyMember(EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String))); var entityType2 = new EntityType("E", "N", DataSpace.CSpace); entityType2.AddKeyMember(EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String))); var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace); associationType.SourceEnd = new AssociationEndMember("S", entityType2); associationType.TargetEnd = new AssociationEndMember("T", entityType1); associationType.MarkPrincipalConfigured(); (new OneToOneConstraintIntroductionConvention()) .Apply(associationType, new DbModel(new EdmModel(DataSpace.CSpace), null)); Assert.NotNull(associationType.Constraint); Assert.Equal(1, associationType.Constraint.ToProperties.Count); }
public void Apply_should_introduce_constraint_when_one_to_one() { var entityType1 = new EntityType(); entityType1.AddKeyMember(EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String))); var entityType2 = new EntityType(); entityType2.AddKeyMember(EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String))); var associationType = new AssociationType(); associationType.SourceEnd = new AssociationEndMember("S", entityType2); associationType.TargetEnd = new AssociationEndMember("T", entityType1); associationType.MarkPrincipalConfigured(); ((IEdmConvention <AssociationType>) new OneToOneConstraintIntroductionConvention()) .Apply(associationType, new EdmModel()); Assert.NotNull(associationType.Constraint); Assert.Equal(1, associationType.Constraint.ToProperties.Count); }
private void ConfigureKey(EntityType entityType) { if (!this._keyProperties.Any <PropertyInfo>()) { return; } if (entityType.BaseType != null) { throw Error.KeyRegisteredOnDerivedType((object)this.ClrType, (object)EntityTypeExtensions.GetClrType(entityType.GetRootType())); } IEnumerable <PropertyInfo> propertyInfos = this._keyProperties.AsEnumerable <PropertyInfo>(); if (!this._isKeyConfigured) { IEnumerable <\u003C\u003Ef__AnonymousType41 <PropertyInfo, int?> > source = this._keyProperties.Select(p => new { PropertyInfo = p, ColumnOrder = this.Property(new PropertyPath(p), new OverridableConfigurationParts?()).ColumnOrder }); if (this._keyProperties.Count > 1 && source.Any(p => !p.ColumnOrder.HasValue)) { throw Error.ModelGeneration_UnableToDetermineKeyOrder((object)this.ClrType); } propertyInfos = source.OrderBy(p => p.ColumnOrder).Select(p => p.PropertyInfo); } foreach (PropertyInfo propertyInfo in propertyInfos) { EdmProperty primitiveProperty = entityType.GetDeclaredPrimitiveProperty(propertyInfo); if (primitiveProperty == null) { throw Error.KeyPropertyNotFound((object)propertyInfo.Name, (object)entityType.Name); } primitiveProperty.Nullable = false; entityType.AddKeyMember((EdmMember)primitiveProperty); } }
public void Generate_should_exclude_sgp_properties_from_corresponding_function_mappings() { var functionMappingGenerator = new ModificationFunctionMappingGenerator(ProviderRegistry.Sql2008_ProviderManifest); var databaseMapping = new DbDatabaseMapping() .Initialize(new EdmModel(DataSpace.CSpace), new EdmModel(DataSpace.SSpace)); var entityType = new EntityType("E", "N", DataSpace.CSpace); var intProperty = EdmProperty.Primitive("Id", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)); intProperty.SetStoreGeneratedPattern(StoreGeneratedPattern.Identity); entityType.AddKeyMember(intProperty); var stringProperty = EdmProperty.Primitive("Name", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); stringProperty.SetStoreGeneratedPattern(StoreGeneratedPattern.Computed); entityType.AddMember(stringProperty); var entitySetMapping = databaseMapping.AddEntitySetMapping( databaseMapping.Model.AddEntitySet("ES", entityType)); var storageEntityTypeMapping = new StorageEntityTypeMapping( new StorageEntitySetMapping(new EntitySet(), databaseMapping.EntityContainerMappings.Single())); storageEntityTypeMapping.AddType(entityType); var storageMappingFragment = new StorageMappingFragment(new EntitySet(), storageEntityTypeMapping, false); storageMappingFragment.AddColumnMapping( new ColumnMappingBuilder(new EdmProperty("C0"), new[] { intProperty })); storageMappingFragment.AddColumnMapping( new ColumnMappingBuilder(new EdmProperty("C1"), new[] { stringProperty })); storageEntityTypeMapping.AddFragment(storageMappingFragment); entitySetMapping.AddTypeMapping(storageEntityTypeMapping); functionMappingGenerator.Generate(entityType, databaseMapping); var modificationFunctionMapping = entitySetMapping.ModificationFunctionMappings.Single(); Assert.NotNull(modificationFunctionMapping); var functionMapping = modificationFunctionMapping.InsertFunctionMapping; Assert.NotNull(functionMapping); Assert.Equal(0, functionMapping.ParameterBindings.Count); Assert.Equal(2, functionMapping.ResultBindings.Count); var function = functionMapping.Function; Assert.NotNull(function); Assert.Equal("E_Insert", function.Name); Assert.Equal(0, function.Parameters.Count); functionMapping = modificationFunctionMapping.UpdateFunctionMapping; Assert.NotNull(functionMapping); Assert.Equal(1, functionMapping.ParameterBindings.Count); Assert.Equal(1, functionMapping.ResultBindings.Count); function = functionMapping.Function; Assert.NotNull(function); Assert.Equal("E_Update", function.Name); Assert.Equal(1, function.Parameters.Count); functionMapping = modificationFunctionMapping.DeleteFunctionMapping; Assert.NotNull(functionMapping); Assert.Equal(1, functionMapping.ParameterBindings.Count); Assert.Null(functionMapping.ResultBindings); function = modificationFunctionMapping.DeleteFunctionMapping.Function; Assert.NotNull(function); Assert.Equal("E_Delete", function.Name); Assert.Equal(1, function.Parameters.Count); }
public void Can_generate_function_mappings_for_entity_type() { var functionMappingGenerator = new ModificationFunctionMappingGenerator(ProviderRegistry.Sql2008_ProviderManifest); var databaseMapping = new DbDatabaseMapping() .Initialize(new EdmModel(DataSpace.CSpace), new EdmModel(DataSpace.SSpace)); var entityType = new EntityType("E", "N", DataSpace.CSpace); var intProperty = EdmProperty.CreatePrimitive("Id", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)); entityType.AddKeyMember(intProperty); var stringProperty = EdmProperty.CreatePrimitive("Name", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(stringProperty); var entitySetMapping = databaseMapping.AddEntitySetMapping( databaseMapping.Model.AddEntitySet("ES", entityType)); var storageEntityTypeMapping = new EntityTypeMapping( new EntitySetMapping(new EntitySet(), databaseMapping.EntityContainerMappings.Single())); storageEntityTypeMapping.AddType(entityType); var storageMappingFragment = new MappingFragment(new EntitySet(), storageEntityTypeMapping, false); storageMappingFragment.AddColumnMapping( new ColumnMappingBuilder(new EdmProperty("C0", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })), new[] { intProperty })); storageMappingFragment.AddColumnMapping( new ColumnMappingBuilder(new EdmProperty("C1", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })), new[] { stringProperty })); storageEntityTypeMapping.AddFragment(storageMappingFragment); entitySetMapping.AddTypeMapping(storageEntityTypeMapping); functionMappingGenerator.Generate(entityType, databaseMapping); var modificationFunctionMapping = entitySetMapping.ModificationFunctionMappings.Single(); Assert.NotNull(modificationFunctionMapping); var functionMapping = modificationFunctionMapping.InsertFunctionMapping; Assert.NotNull(functionMapping); Assert.Equal(2, functionMapping.ParameterBindings.Count); Assert.Null(functionMapping.ResultBindings); var function = functionMapping.Function; Assert.NotNull(function); Assert.Equal("E_Insert", function.Name); Assert.Equal(2, function.Parameters.Count); functionMapping = modificationFunctionMapping.UpdateFunctionMapping; Assert.NotNull(functionMapping); Assert.Equal(2, functionMapping.ParameterBindings.Count); Assert.Null(functionMapping.ResultBindings); function = functionMapping.Function; Assert.NotNull(function); Assert.Equal("E_Update", function.Name); Assert.Equal(2, function.Parameters.Count); functionMapping = modificationFunctionMapping.DeleteFunctionMapping; Assert.NotNull(functionMapping); Assert.Equal(1, functionMapping.ParameterBindings.Count); Assert.Null(functionMapping.ResultBindings); function = modificationFunctionMapping.DeleteFunctionMapping.Function; Assert.NotNull(function); Assert.Equal("E_Delete", function.Name); Assert.Equal(1, function.Parameters.Count); }