/// <summary> /// Adds a property backed by and indexer to this entity type. /// </summary> /// <param name="entityType"> The entity type. </param> /// <param name="name"> The name of the property to add. </param> /// <param name="propertyType"> The type of value the property will hold. </param> /// <param name="setTypeConfigurationSource"> Indicates whether the type configuration source should be set. </param> /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param> /// <returns> The newly created property. </returns> public static IConventionProperty AddIndexerProperty( [NotNull] this IConventionEntityType entityType, [NotNull] string name, [NotNull] Type propertyType, bool setTypeConfigurationSource = true, bool fromDataAnnotation = false) { Check.NotNull(entityType, nameof(entityType)); var indexerPropertyInfo = entityType.FindIndexerPropertyInfo(); if (indexerPropertyInfo == null) { throw new InvalidOperationException( CoreStrings.NonIndexerEntityType(name, entityType.DisplayName(), typeof(string).ShortDisplayName())); } return(entityType.AddProperty(name, propertyType, indexerPropertyInfo, setTypeConfigurationSource, fromDataAnnotation)); }
/// <summary> /// Adds a property to this entity type. /// </summary> /// <param name="entityType"> The entity type to add the property to. </param> /// <param name="name"> The name of the property to add. </param> /// <param name="propertyType"> The type of value the property will hold. </param> /// <param name="setTypeConfigurationSource"> Indicates whether the type configuration source should be set. </param> /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param> /// <returns> The newly created property. </returns> public static IConventionProperty AddProperty( [NotNull] this IConventionEntityType entityType, [NotNull] string name, [NotNull] Type propertyType, bool setTypeConfigurationSource = true, bool fromDataAnnotation = false) => entityType.AddProperty(name, propertyType, null, setTypeConfigurationSource, fromDataAnnotation);