public void IsRequired_when_dependent_property_nullable() { var entityType = new EntityType("E"); entityType.SetKey(entityType.AddProperty("Id", typeof(int))); var dependentProp = entityType.AddProperty("P", typeof(int?)); var foreignKey = new ForeignKey(entityType.GetKey(), new[] { dependentProp }); Assert.False(foreignKey.IsRequired); }
public virtual KeyMetadataBuilder Properties([NotNull] Expression <Func <TEntity, object> > keyExpression) { Check.NotNull(keyExpression, "keyExpression"); EntityType.SetKey( keyExpression.GetPropertyAccessList() .Select(pi => EntityType.TryGetProperty(pi.Name) ?? EntityType.AddProperty(pi)) .ToArray()); return(new KeyMetadataBuilder(EntityType.GetKey())); }
public void FK_properties_are_marked_as_requiring_original_values() { var entityType = new EntityType(typeof(FullNotificationEntity)); entityType.SetKey(entityType.AddProperty("Id", typeof(int))); Assert.Equal(-1, entityType.GetProperty("Id").OriginalValueIndex); entityType.AddForeignKey(entityType.GetKey(), new[] { entityType.AddProperty("Id", typeof(int)) }); Assert.Equal(0, entityType.GetProperty("Id").OriginalValueIndex); }
public void Setting_foreign_key_properties_should_update_existing_properties() { var entityType = new EntityType(typeof(Order)); entityType.SetKey(entityType.AddProperty(Order.CustomerIdProperty)); var newIdProperty = entityType.AddProperty(Order.CustomerIdProperty); var property2 = entityType.AddProperty(Order.CustomerUniqueProperty); entityType.AddForeignKey(entityType.GetKey(), new[] { newIdProperty, property2 }); Assert.Equal(new[] { newIdProperty, property2 }, entityType.Properties.ToArray()); }
public void Add_foreign_key() { var entityType = new EntityType(typeof(Order)); entityType.SetKey(entityType.AddProperty(Order.IdProperty)); var foreignKey = entityType.AddForeignKey( entityType.GetKey(), new[] { entityType.AddProperty(Order.CustomerUniqueProperty) }); Assert.True(entityType.ForeignKeys.Contains(foreignKey)); }
public void Setting_key_properties_should_update_existing_properties() { var entityType = new EntityType(typeof(Customer)); entityType.AddProperty(Customer.IdProperty); var newIdProperty = entityType.AddProperty(Customer.IdProperty); var property2 = entityType.AddProperty(Customer.NameProperty); entityType.SetKey(newIdProperty, property2); Assert.True(new[] { newIdProperty, property2 }.SequenceEqual(entityType.Properties)); }
public void Can_set_and_reset_key() { var entityType = new EntityType(typeof(Customer)); var property1 = entityType.AddProperty(Customer.IdProperty); var property2 = entityType.AddProperty(Customer.NameProperty); entityType.SetKey(property1, property2); Assert.True(new[] { property1, property2 }.SequenceEqual(entityType.GetKey().Properties)); Assert.True(new[] { property1, property2 }.SequenceEqual(entityType.Properties)); entityType.RemoveProperty(property1); Assert.True(new[] { property2 }.SequenceEqual(entityType.GetKey().Properties)); Assert.True(new[] { property2 }.SequenceEqual(entityType.Properties)); property1 = entityType.AddProperty(Customer.IdProperty); entityType.SetKey(property1); Assert.True(new[] { property1 }.SequenceEqual(entityType.GetKey().Properties)); Assert.True(new[] { property1, property2 }.SequenceEqual(entityType.Properties)); }
public void Can_create_foreign_key() { var entityType = new EntityType("E"); var dependentProp = entityType.AddProperty("P", typeof(int)); var principalProp = entityType.AddProperty("Id", typeof(int)); entityType.SetKey(principalProp); var foreignKey = new ForeignKey(entityType.GetKey(), new[] { dependentProp }) { IsUnique = true, }; Assert.Same(entityType, foreignKey.ReferencedEntityType); Assert.Same(principalProp, foreignKey.ReferencedProperties.Single()); Assert.Same(dependentProp, foreignKey.Properties.Single()); Assert.True(foreignKey.IsUnique); }
public void FK_back_pointer_is_fixed_up_as_FK_is_added() { var entityType = new EntityType(typeof(Customer)); var property = entityType.AddProperty(Customer.IdProperty); entityType.SetKey(property); var foreignKey = entityType.AddForeignKey(entityType.GetKey(), property); Assert.Same(entityType, foreignKey.EntityType); Assert.Same(entityType, property.EntityType); entityType.RemoveForeignKey(foreignKey); // Currently property is not removed when FK is removed Assert.Empty(entityType.ForeignKeys); Assert.Same(property, entityType.Properties.Single()); Assert.Same(entityType, foreignKey.EntityType); // TODO: Throw here? Assert.Same(entityType, property.EntityType); }