/// <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 virtual EntityTypeConfiguration HasKey(PropertyInfo keyProperty) { if (BaseType != null && BaseType.Keys().Any()) { 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); }
/// <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 virtual EntityTypeConfiguration HasKey(PropertyInfo keyProperty) { if (BaseType != null && BaseType.Keys().Any()) { throw Error.InvalidOperation(SRResources.CannotDefineKeysOnDerivedTypes, FullName, BaseType.FullName); } // Add the enum key if the property type is enum if (keyProperty.PropertyType.IsEnum) { ModelBuilder.AddEnumType(keyProperty.PropertyType); EnumPropertyConfiguration enumConfig = AddEnumProperty(keyProperty); // keys are always required enumConfig.IsRequired(); if (!_enumKeys.Contains(enumConfig)) { _enumKeys.Add(enumConfig); } } else { PrimitivePropertyConfiguration propertyConfig = AddProperty(keyProperty); // keys are always required propertyConfig.IsRequired(); if (!_keys.Contains(propertyConfig)) { _keys.Add(propertyConfig); } } return(this); }