public void KeyAttribute_throws_when_setting_composite_primary_key() { var entityTypeBuilder = CreateInternalEntityTypeBuilder <B>(); var keyAttributeConvention = new KeyAttributeConvention(); Assert.Null(entityTypeBuilder.Metadata.FindDeclaredPrimaryKey()); var idPropertyBuilder = entityTypeBuilder.Property("Id", typeof(int), ConfigurationSource.Explicit); var myPrimaryKeyPropertyBuilder = entityTypeBuilder.Property("MyPrimaryKey", typeof(int), ConfigurationSource.Explicit); keyAttributeConvention.Apply(idPropertyBuilder); Assert.Equal(1, entityTypeBuilder.Metadata.FindDeclaredPrimaryKey().Properties.Count); Assert.Equal("Id", entityTypeBuilder.Metadata.FindDeclaredPrimaryKey().Properties[0].Name); keyAttributeConvention.Apply(myPrimaryKeyPropertyBuilder); Assert.Equal(2, entityTypeBuilder.Metadata.FindPrimaryKey().Properties.Count); Assert.Equal("Id", entityTypeBuilder.Metadata.FindPrimaryKey().Properties[0].Name); Assert.Equal("MyPrimaryKey", entityTypeBuilder.Metadata.FindPrimaryKey().Properties[1].Name); Assert.Equal( CoreStrings.CompositePKWithDataAnnotation(entityTypeBuilder.Metadata.DisplayName()), Assert.Throws <InvalidOperationException>(() => keyAttributeConvention.Apply(entityTypeBuilder.ModelBuilder)).Message); }
public void Sets_id_member_when_key_attribute_present(string memberName) { MemberInfo memberInfo = typeof(SimpleRecord) .GetTypeInfo() .GetProperty(memberName); bool isIdMember = memberInfo.IsDefined(typeof(KeyAttribute)); var keyAttributeConvention = new KeyAttributeConvention(); var bsonClasspMap = new BsonClassMap <SimpleRecord>(); BsonMemberMap bsonMemberMap = bsonClasspMap.MapMember(typeof(SimpleRecord).GetTypeInfo().GetProperty(memberName)); keyAttributeConvention.Apply(bsonMemberMap); Assert.Equal(isIdMember, bsonClasspMap.IdMemberMap == bsonMemberMap); }