/// <summary> /// Configures the referential constraint for the navigation property. The dependent property will be added /// as non-nullable primitive property into the declaring entity type if it's not in the entity type. /// </summary> /// <param name="constraint">The dependent and principal property info pair.</param> public NavigationPropertyConfiguration HasConstraint(KeyValuePair <PropertyInfo, PropertyInfo> constraint) { if (constraint.Key == null) { throw Error.ArgumentNull("dependentPropertyInfo"); } if (constraint.Value == null) { throw Error.ArgumentNull("principalPropertyInfo"); } // OData V3 spec: The multiplicity of navigation property with referential constraint MUST be 1 or 0..1. if (Multiplicity == EdmMultiplicity.Many) { throw Error.NotSupported(SRResources.ReferentialConstraintOnManyNavigationPropertyNotSupported, Name, DeclaringEntityType.ClrType.FullName); } if (ValidateConstraint(constraint)) { return(this); } PrimitivePropertyConfiguration dependentConfiguration = DeclaringEntityType.AddProperty(constraint.Key); // Because principal properties and keys are required. So as dependent properties. dependentConfiguration.IsRequired(); _referentialConstraint.Add(constraint); return(this); }
/// <summary> /// Configures the key property(s) for this entity type. /// </summary> /// <param name="keyProperty">The property to be added to the key properties of this entity type.</param> /// <returns>Returns itself so that multiple calls can be chained.</returns> public IEntityTypeConfiguration HasKey(PropertyInfo keyProperty) { if (BaseType != null) { throw Error.InvalidOperation(SRResources.CannotDefineKeysOnDerivedTypes, FullName, BaseType.FullName); } PrimitivePropertyConfiguration propertyConfig = AddProperty(keyProperty); // keys are always required propertyConfig.IsRequired(); if (!_keys.Contains(propertyConfig)) { _keys.Add(propertyConfig); } return(this); }