public void Can_only_override_existing_key_explicitly_using_property_names() { var entityType = new Model().AddEntityType(typeof(Order)); var entityBuilder = new InternalEntityBuilder(entityType, new InternalModelBuilder(new Model(), null)); entityType.SetPrimaryKey(new[] { entityType.GetOrAddProperty(Order.IdProperty), entityType.GetOrAddProperty(Order.CustomerIdProperty) }); Assert.Null(entityBuilder.Key(new[] { Order.IdProperty.Name }, ConfigurationSource.DataAnnotation)); Assert.Equal(new[] { Order.IdProperty.Name, Order.CustomerIdProperty.Name }, entityType.GetPrimaryKey().Properties.Select(p => p.Name).ToArray()); Assert.NotNull(entityBuilder.Key(new[] { Order.IdProperty.Name }, ConfigurationSource.Explicit)); Assert.Equal(Order.IdProperty.Name, entityType.GetPrimaryKey().Properties.Single().Name); }
public void Default_nullability_of_property_is_based_on_nullability_of_CLR_type_and_property_being_part_of_primary_key() { var entityType = new Model().AddEntityType(typeof(object)); var stringProperty = entityType.AddProperty("stringName", typeof(string)); var nullableIntProperty = entityType.AddProperty("nullableIntName", typeof(int?)); var intProperty = entityType.AddProperty("intName", typeof(int)); Assert.Null(stringProperty.IsNullable); Assert.True(((IProperty)stringProperty).IsNullable); Assert.Null(stringProperty.IsNullable); Assert.True(((IProperty)nullableIntProperty).IsNullable); Assert.Null(intProperty.IsNullable); Assert.False(((IProperty)intProperty).IsNullable); entityType.SetPrimaryKey(stringProperty); Assert.Null(stringProperty.IsNullable); Assert.False(((IProperty)stringProperty).IsNullable); }